Skip to main content
The const declaration creates a block-scoped, read-only reference to a value. It establishes an immutable binding, meaning the variable identifier cannot be reassigned to a new value, nor can it be redeclared within the same lexical scope.

Initialization Requirement

Because the binding cannot be altered after creation, a const declaration requires an immediate initializer. Declaring a const without an assignment throws a SyntaxError during the parsing phase.

Reassignment and Redeclaration

Attempting to reassign a const identifier throws a runtime TypeError.
Attempting to redeclare an identifier that already exists in the same lexical scope throws a parse-time SyntaxError.

Immutable Binding vs. Immutable Value

The const keyword guarantees an immutable binding, not an immutable value. If the assigned value is a reference type (such as an Object or an Array), the underlying data structure is not frozen. The properties or elements of that structure can be mutated, provided the variable identifier itself is not reassigned to a new memory address.

Block Scope and the Temporal Dead Zone (TDZ)

const declarations are block-scoped, meaning their visibility is limited to the nearest enclosing block { ... }.
During execution context creation, const declarations are hoisted to the top of their block scope but remain uninitialized. The period between entering the scope and the actual lexical declaration is known as the Temporal Dead Zone (TDZ). Accessing the identifier within the TDZ throws a ReferenceError.

Global Object Context

When executed in a global script context (such as a standard <script> tag in a browser), const declarations do not create properties on the global object (e.g., window). This contrasts with var, which does append its identifier to the global environment record. (Note: In Node.js, top-level declarations are scoped to the module wrapper by default, meaning neither var nor const creates a property on the global object.)
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More