Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

In TypeScript, let and const are both block-scoped declarations. The key difference is whether you can assign a new value to the variable: use let when reassignment is part of the logic, and const when it is not. A const binding does not make an object or array immutable.

How are let and const different?

Declaration Can the binding be reassigned? Scope What happens to object contents?
let Yes Block scope Contents can be changed if the value is mutable.
const No, after initialization Block scope Contents can still be changed if the referenced value is mutable.

The TypeScript Handbook describes let and const as block-scoped, so neither declaration is visible outside the block in which it appears. This differs from var, which is function-scoped. See the Handbook’s variable declaration guide.

When should you use each one?

Use const when you do not need to reassign the variable

The TypeScript Handbook recommends that declarations you do not plan to modify use const. This is guidance, not a syntax requirement; it makes the intended data flow clearer by preventing accidental reassignment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const taxRate = 0.08;
// taxRate = 0.1; // Error: cannot reassign a const binding

Use let when reassignment is intentional

If your logic updates a variable with a different value, declare it with let.

let total = 0;
total += 12; // Reassignment is allowed with let

Does const make an object or array immutable?

No. const protects the binding—the name cannot be made to refer to a different value. It does not freeze the object or array the binding refers to. Mutable properties can still be changed:

const settings = { theme: "light" };
settings.theme = "dark"; // Allowed: the binding has not changed
// settings = { theme: "dark" }; // Error: cannot reassign the binding

This distinction is useful when deciding what protection your code needs: const prevents rebinding, while property or collection restrictions require type-level constructs such as readonly or as const.

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

How do readonly and as const differ from const?

readonly restricts properties or collections in the type

Use a readonly property when code should not assign a new value to that property through the declared type. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
interface Point {
  readonly x: number;
  readonly y: number;
}

const point: Point = { x: 1, y: 2 };
// point.x = 3; // TypeScript error: x is readonly

The variable declaration uses const; the interface’s readonly modifiers restrict assignments to the properties at the TypeScript type level. The Handbook sums up the distinction: “Variables use const whereas properties use readonly.” See TypeScript’s Interfaces Handbook.

as const preserves literal types and readonly literal structure

A const assertion is a type assertion on a literal expression, not a variable declaration. TypeScript 3.4 introduced as const to prevent literal widening; object-literal properties become readonly and array literals become readonly tuples.

const palette = { primary: "blue" } as const;
// primary is readonly and has the literal type "blue"

Neither readonly nor as const should be understood as runtime freezing or a guarantee of deep immutability. The TypeScript 3.4 release notes show that referenced mutable values can still be changed.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What does this mean at runtime?

TypeScript is a static typechecker for JavaScript that checks code before it runs, as explained in the TypeScript Handbook introduction. The practical choice between let and const controls whether the binding can be reassigned; it does not add a TypeScript-specific runtime object-freezing guarantee.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.