Repeat

Last update in 2/2020

Repeating string can easily be done with built in repeat method on JavaScript String prototype.

'a'.repeat(3) // 'aaa'

It accepts numbers from 0 to +infinity (0 will return empty string) and if you pass negative number as argument it will throw RangeError.

'a'.repeat(-1) // RangeError
'a'.repeat(0) // ''