

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Arrays
incomplete
2: Array Length
incomplete
3: Array Spread
incomplete
4: Includes
incomplete
5: For...of Loops
incomplete
6: Slicing Arrays
incomplete
7: const Arrays
incomplete
8: Destructure
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Like objects, the contents of const arrays can be modified! Again, they just can't be reassigned. That means we can add and remove elements, but we can't set a new array value with the assignment operator: =.
const drinks = [];
drinks.push("lemonade");
// ["lemonade"]
drinks[0] = "soda";
// ["soda"]
drinks = ["root beer"];
// TypeError: Assignment to constant variable.
Personally, I'm not a fan of this quirk of the JavaScript language because, to me, const implies that a value won't change at all. However, in the case of an array all the contents can be modified as long as the assignment operator is never used to reassign the array itself.