The repeat() method returns a new string that consists of the specified number of copies of the string.
For example:
const catSound="meow";
console.log(Cat makes sounds "${catSound.repeat(5)}");
The console shows as below:
'Cat makes sounds "meowmeowmeowmeowmeow"' //"meow" is repeated 5 times as specified in the brackets.
If you specify the number "0"
'Cat makes sounds ""'
If you specify a negative number (e.g. -1) or an infinity number (e.g. 1/0)
It returns "Range Error."
Top comments (0)