const is used to declare constant bindings — variables whose identifier cannot be reassigned, but whose contents may still change (if it’s an object or array).
1. What const does — simple definition
- Creates a block-scoped variable
- Must be initialized at declaration time
- The binding cannot be reassigned
- Works perfectly with objects and arrays (the object can change, but the variable name cannot be reassigned)
Example:
2. Basic Syntax
THIS is NOT allowed:
3. Block Scope
const obeys block scope exactly like let.
4. Constants cannot be reassigned
Even redeclaring is not allowed:
5. BUT Arrays and Objects declared with const can be modified
const prevents reassignment, NOT mutation.
