Question
If I use const
to declare an array can I still add/update the elements in the array?
Answer
Yes you can. Since you’re only modifying the array and not redefining it you are allowed to modify its contents by adding/removing/updating the elements in the array. Remember, while you can modify the array you cannot redefine it. Example:
// This works
const testArray = [1, 2];
testArray[2] = 3;
// This gives an error
testArray = [4, 5, 6];