Files
it-know-how/typescript/bits/02-const-and-assignment.md
2026-03-27 12:58:01 +01:00

637 B
Executable File

const and Assignment

TypeScript uses const, let, and var for variable declarations. Modern code usually prefers const and let.

const

const apiBase = 'https://example.com';
  • const means the binding cannot be reassigned.
  • You can still mutate object contents unless frozen.
const config = { retries: 2 };
config.retries = 3; // allowed
// config = {}; // not allowed

Assignment Operator =

let count = 0;
count = count + 1;
  • = assigns a new value to a variable.

Python Comparison

Python has no enforced const; TypeScript enforces no-reassign when const is used.