DEV Community


repeat() - JavaScript

JavaScript developer✌
・1 min read

The repeat() is called on a string which takes one argument (number of times the string needs to be repeated) and returns a new string , containing the repetitions of the string on which it was called (argument times), concatenated together.

Note - The argument passed must be non-negative and the new string formed must not overflow the maximum string size.

'#'.repeat(3) returns '###'

Discussion (1)

yujiri8 profile image
Ryan Westlund

So that's how it's done! I tried to do this the Python way and it gave me NaN.