Typescript: why can't i reassign a variable declared with 'const'?


const x = 10;
x = 20;  // Error: Cannot assign to 'x' because it is a constant.

let x = 10;
x = 20;  // Correct usage with 'let'
In TypeScript (and modern JavaScript), variables declared with 'const' are read-only. If you need a variable that can be reassigned, use 'let'.

Beginner's Guide to TypeScript