Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Let Hoisting

Variables declared with var are hoisted to the top of their scope and can be initialized at any point.

This implies that you can utilize the variable before it is formally declared:

Example

This is acceptable:

carName = “Volvo”;
var carName;

For a deeper understanding of hoisting, delve into the chapter on JavaScript Hoisting.

Variables declared with let are indeed hoisted to the top of the block, but they remain uninitialized.

Consequently, attempting to use a let variable before its declaration will lead to a ReferenceError:

Example

carName = “Saab”;
let carName = “Volvo”;