mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculum): clarify RangeError example in debugging lecture (#63964)
This commit is contained in:
committed by
GitHub
parent
014882c92d
commit
cce4f57022
+3
-3
@@ -50,14 +50,14 @@ This example will result in a `developerObj.map is not a function` error because
|
||||
|
||||
The last common error we will look at is the `RangeError`.
|
||||
|
||||
A `RangeError` happens when your code tries to use a value that’s outside the range of what JavaScript can handle. Here is an example of trying to assign an invalid index to the length of the array:
|
||||
A `RangeError` happens when your code tries to use a value that’s outside the range of what JavaScript can handle. Here is an example of assigning an invalid value to an array's length:
|
||||
|
||||
```js
|
||||
const arr = [];
|
||||
arr.length = -1;
|
||||
```
|
||||
|
||||
Since `-1` is not a valid index used for arrays, this will result in a `RangeError`.
|
||||
Since an array's `length` has to be a non-negative integer, setting it to `-1` triggers a `RangeError`.
|
||||
|
||||
As you continue to program in JavaScript, just be aware of these different types of errors you will probably encounter and why they are happening.
|
||||
|
||||
@@ -137,7 +137,7 @@ The error happens because the variable is being treated like a function when it'
|
||||
|
||||
## --text--
|
||||
|
||||
Which error occurs when you try to access an array index that doesn't exist?
|
||||
Which error occurs when you assign an invalid value, such as `-1`, to an array's `length`?
|
||||
|
||||
## --answers--
|
||||
|
||||
|
||||
Reference in New Issue
Block a user