Skip to content

Latest commit

 

History

History
17 lines (11 loc) · 754 Bytes

does_the_const_variable_make_the_value_immutable.md

File metadata and controls

17 lines (11 loc) · 754 Bytes

Does the const variable make the value immutable?

No, const only ensures that the variable identifier cannot be reassigned. It does not make the value immutable. If the value is an object or array, its properties or elements can still be modified.

Example:

const arr = [1, 2, 3];
arr.push(4);  // Works fine
arr = [4, 5, 6];  // Error: Assignment to constant variable

Tags: intermediate, JavaScript, Variables

URL: https://www.tiktok.com/@jsmentoring/photo/7470295229015264544