Saturday, June 13, 2026
HomeLanguagesJavascriptJavaScript RangeError – Repeat count must be non-negative

JavaScript RangeError – Repeat count must be non-negative

This JavaScript exception repeat count must be non-negative occurs if the argument passed to String.prototype.repeat() method is a negative number.

Message:

RangeError: argument out of range
RangeError: repeat count must be non-negative (Firefox)
RangeError: Invalid count value (Chrome)

Error Type:

RangeError

Cause of Error: The repeat() method has a parameter that indicates the number of times to repeat the string. It should be in the range 0 to Infinity and cannot be a negative number.

Example 1: In this example, the parameter’s value passed is a negative value, So the error has occurred.

Javascript




'GFG'.repeat(-1); // error here


Output(in console):

RangeError: Invalid count value

Example 2: In this example, the parameter’s value passed is a negative value, So the error has occurred.

Javascript




let gfg = "This is neveropen";
gfg.repeat(-100); // error here


Output(in console):

RangeError: Invalid count value
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS