const name = 1;
name = 2;
When executing this JavaScript I get an error :
TypeError: Assignment to constant variable.
at Object.<anonymous> (/home/user01/JavaScript/scope.js:2:6)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
But, on executing below statements, code executes successfully.
const arr = [1,2,3];
arr[1] = 5;
Why are we able to modify an array even if it is declared as constant.