Side-by-side comparison of RangeError and ReferenceError — understand the differences, causes, and fixes.
RangeErrorA value is not within the expected range, such as an invalid array length or exceeding the call stack size.
A numeric value or other parameter is outside the set of allowed values. This includes passing negative numbers where positive is required, exceeding recursion limits, or using values outside precision bounds.
Validate inputs before passing them to functions. Add bounds checking for numeric values. If caused by recursion, add a base case or convert to iteration.
ReferenceErrorA reference was made to a variable that does not exist in the current scope.
You tried to use a variable that has not been declared, is not in scope, or was accessed before its declaration (temporal dead zone). This can also happen with misspelled variable names.
Declare the variable before using it with let, const, or var. Check for typos in variable names. Ensure the variable is in scope where you are accessing it. Import missing modules.