const
最終更新
const foo = 123;
foo = 456; // ERROR: 代入の左側に定数を置くことはできませんconst foo = 123;
if (true) {
const foo = 456; // Allowed as its a new variable limited to this `if` block
}const foo = { bar: 123 };
foo = { bar: 456 }; // ERROR : Left hand side of an assignment expression cannot be a constantconst foo = { bar: 123 };
foo.bar = 456; // Allowed!
console.log(foo); // { bar: 456 }