Differentiate between 'let' and 'const' in TypeScript

Instruction: Explain the difference between 'let' and 'const' keywords in TypeScript, including their scope and mutability.

Context: This question evaluates the candidate's knowledge of variable declarations in TypeScript and their understanding of block scope and immutability.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

Both let and const declare block-scoped bindings. let permits reassignment; const requires an initializer and prevents reassignment of that binding. Neither makes an object deeply immutable.

let count = 0; count = count + 1; const settings = { retries: 2 }; settings.retries = 3; // allowed: the object remains mutable const labels =...

Related Questions