Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

The let and const Keywords

Variables declared with let and const are hoisted to the top of their block, but they are not initialized.

This means the variable is known to the block, but cannot be used until it is declared.

Attempting to use a let or const variable before it is declared will result in a ReferenceError.

The variable remains in a “temporal dead zone” from the start of the block until it is initialized.

Example

This will cause a ReferenceError:

carName = “Volvo”;
let carName;

Using a const variable before it is declared results in a syntax error, causing the code to fail to execute.

Example

This code will not execute.

carName = “Volvo”;
const carName;