const declarations
The other new ES6 declaration type supported in TypeScript is const
. A const
variable may not be assigned to, and must be initialized where it is declared. This is useful for declarations where you don’t want to change the value after its initialization:
const halfPi = Math.PI / 2;
halfPi = 2; // Error, can't assign to a `const`
const
is only available when targeting ECMAScript 6 (—target ES6
).