A const
variable cannot be re-assigned, like a property readonly
.
Essentially, when you define a property, you can use readonly
to prevent reassignment. This is actually just a compile time check.
const
( JavaScript const
), .
, , , - .
const x = 5;
x = 7;
class Example {
public readonly y = 6;
}
var e = new Example();
e.y = 4;
... " " - , .
const myArr = [1, 2, 3];
myArr = [4, 5, 6]
myArr.push(4);
myArr[0] = 9;