Widely availableSupported across all major browsers. Safe to use in production.

Overview

The let and const declarations define block-scoped variables.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
21
12
36
5.1
25
5
Other

The let declaration declares re-assignable, block-scoped local variables, optionally initializing each to a value.

49
14
44
10
49
10
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Notes 2 item(s)
Implementation note
  • Before Firefox 13, `const` is implemented, but re-assignment is not failing.
  • Before Firefox 46, a `TypeError` was thrown on redeclaration instead of a `SyntaxError`.
Notes 3 item(s)
Limitation
  • This browser only partially implements this feature
Removed
  • This feature was removed in a later browser version (49)
Implementation note
  • Strict mode is required.
Notes 3 item(s)
Limitation
  • This browser only partially implements this feature
Removed
  • This feature was removed in a later browser version (14)
Implementation note
  • In Edge 12 and 13, `let` within a `for` loop initializer does not create a separate variable for each loop iteration as defined by ES2015. Instead, it behaves as though the loop were wrapped in a scoping block with the `let` immediately before the loop.
Notes 3 item(s)
Implementation note
  • Before Firefox 44, `let` is only available to code blocks in HTML wrapped in a `<script type="application/javascript;version=1.7">` block (or higher version) and has different semantics (e.g. no temporal dead zone).
  • Before Firefox 46, a `TypeError` is thrown on redeclaration instead of a `SyntaxError`.
  • Firefox 54 adds support of `let` in workers.
Notes 3 item(s)
Limitation
  • This browser only partially implements this feature
Removed
  • This feature was removed in a later browser version (49)
Implementation note
  • Strict mode is required.

Syntax

JAVASCRIPT
// let: can be reassigned
let count = 0;
count = 1; // OK

// const: cannot be reassigned
const PI = 3.14;
// PI = 3; // Error

// Object properties can be changed even with const
const user = { name: 'Taro' };
user.name = 'Hanako'; // OK

Live demo

statetransition with let

reassignmentpossible let variable usage, timebetween. and and also to state that change variantchild inspect it..

PreviewFullscreen

Const and not-

wordvariable is reassignment in.error that emitlivesimul-tion row.. with const

PreviewFullscreen

Const object. Propertychange

wordobjectbody is lock. that, middle. Property is changepossible and inspect it.. with const

PreviewFullscreen

Use cases

  • Using Let and const

    The let and const declarations define block-scoped variables.

Cautions

  • No specific concerns. Stable across all major browsers.

Accessibility

  • When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.

Powered by web-features