Understanding const Objects and Arrays in Javascript


Objects and arrays declared with const can still have their contents modified.

Source Code

const person = {name: 'John'};
person.name = 'Jane'; // This is allowed
console.log(person); // {name: "Jane"}

const numbers = [1, 2, 3];
numbers.push(4); // This is allowed
console.log(numbers); // [1, 2, 3, 4]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments