October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

Difference Between `let` and `const` in TypeScript

Both let and const are block scoped in TypeScript. Choose let for reassignment and const for a binding that should stay fixed; use readonly or as const for type-level restrictions on properties and literals.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In TypeScript, both let and const declare block-scoped variables. The key difference is reassignment: use let when the variable must later hold a different value; use const when its binding should stay fixed. A const binding does not, by itself, make an object or array immutable.

How do let and const differ?

let allows reassignment after initialization. const requires an initial value and prevents the declared name from being assigned a different value later. TypeScript checks these rules, and the declarations also have corresponding JavaScript binding behavior; they do not provide a special object-freezing feature. See the TypeScript Handbook’s variable declaration guide and its introduction to TypeScript’s static typechecking.

As an Amazon Associate I earn from qualifying purchases.

const taxRate = 0.08;
// taxRate = 0.1; // Error: cannot reassign a const binding

let total = 0;
total += 12; // Allowed: let can be reassigned

When should you use each one?

Use const when the binding does not need reassignment

The TypeScript Handbook recommends that declarations other than those you plan to modify use const. This is guidance, not a syntax requirement: it makes it easier to see which names remain bound to their initial values and can make data flow more predictable.

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

Use let when reassignment is intentional

Choose let when your logic needs to assign a new value to the same variable, such as updating a running total or tracking a changing state. If reassignment is not part of the intended logic, prefer const.

Do they have different scopes?

No. Both let and const are block scoped: a name declared inside a block, such as an if block, is not available outside that block. Scope is not a reason to choose one over the other. The TypeScript Handbook contrasts them with var, which is function scoped.

Does const make an object or array immutable?

No. const fixes the binding, not every value reachable through it. You can change mutable properties of an object or contents of an array, but you cannot reassign the variable to refer to a different object or array.

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
const settings = { theme: "light" };
settings.theme = "dark"; // Allowed: the binding is unchanged
// settings = { theme: "dark" }; // Error: rebinding the const
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How are readonly and as const different?

Use readonly in a type when you want TypeScript to disallow assignments to particular properties or array elements through that type. A const declaration controls whether the variable binding can be reassigned; it does not make the properties readonly.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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; // Error: x is readonly

The Handbook puts the distinction succinctly: “Variables use const whereas properties use readonly.” Read more in the TypeScript Handbook’s interfaces guide.

as const is different again: it is a const assertion on a literal expression, not a variable declaration. It preserves literal types rather than widening them, and gives object-literal properties readonly types and array literals readonly tuple types.

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

These are TypeScript type-level constraints, not runtime freezing. A const assertion also does not make referenced mutable values deeply immutable. The behavior and its limitation are described in the TypeScript 3.4 release notes.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.