Skip to content
Related Articles

Related Articles

Improve Article

JavaScript RangeError – Repeat count must be non-negative

  • Last Updated : 31 Jul, 2020
Geek Week

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 which indicates the number of times to repeat the string. It should be in 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.



HTML




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

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.

HTML




<script
    var gfg = "This is GeeksforGeeks";
    gfg.repeat(-100); // error here
</script>

Output(in console):

RangeError: Invalid count value

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :