Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 972 Bytes

File metadata and controls

33 lines (22 loc) · 972 Bytes

const

The const keyword is used to create a read-only reference to a value.

const NAME = 'Bob';

The value it holds is still mutable, but the variable identifier cannot be reassigned:

const NAME = 'Bob';

NAME = 'Steve';
// TypeError: Assignment to constant variable

or redeclared:

const NAME = 'Bob';

const NAME = 'Sally';
// SyntaxError: Identifier 'NAME' has already been declared

Variables declared using the const keyword are block-scoped, meaning they are only accessible within the current block, and any contained sub-blocks.

The value that a variable declared using const holds can only be referenced after it has been defined. This is known as the Temporal Dead Zone.