JavaScript RangeError – Repeat count must be less than infinity
This JavaScript exception repeat count must be less than infinity occurs if the passed argument of String.prototype.repeat() method is infinity.
Message:
RangeError: argument out of range (Edge) RangeError: repeat count must be less than infinity and not overflow maximum string size (Firefox) RangeError: Invalid count value (Chrome)
Error Type:
RangeError
Cause of the error: The count parameter of String.prototype.repeat() method passed is either less than 0 or greater than infinity.
Example 1: In this example, the parameter passed is 4, So the error has not occurred.
HTML
<!DOCTYPE html> < html > < body style = "text-align: center;" > < h1 style = "color: green;" > GeeksforGeeks </ h1 > < p > JavaScript RangeError Repeat count must be less than infinity </ p > < button onclick = "Geeks();" > click here </ button > < p id = "GFG_DOWN" ></ p > < script > var el_down = document.getElementById("GFG_DOWN"); function Geeks() { try { "GFG".repeat(4); el_down.innerHTML = "'Repeat count " + "must be less than infinity' " + "error has not occurred"; } catch (e) { el_down.innerHTML = "'Repeat count " + "must be less than infinity' " + "error has occurred"; } } </ script > </ body > </ html > |
Output:
Example 2: In this example, the parameter passed is 232, So the error has occurred,
HTML
<!DOCTYPE html> < html > < body style = "text-align: center;" > < h1 style = "color: green;" > GeeksforGeeks </ h1 > < p > JavaScript RangeError Repeat count must be less than infinity </ p > < button onclick = "Geeks();" > click here </ button > < p id = "GFG_DOWN" ></ p > < script > var el_down = document.getElementById("GFG_DOWN"); function Geeks() { try { "GFG".repeat(2 ** 32); el_down.innerHTML = "'Repeat count " + "must be less than infinity' " + "error has not occurred"; } catch (e) { el_down.innerHTML = "'Repeat count " + "must be less than infinity' " + "error has occurred"; } } </ script > </ body > </ html > |
Output: