Variables defined with let and const are hoisted to the top of the block, but not initialized.
Meaning: The block of code is aware of the variable, but it cannot be used until it has been declared.
Using a let variable before it is declared will result in a ReferenceError.
The variable is in a "temporal dead zone" from the start of the block until it is declared:
Example
This will result in a
carName = "Volvo";
let carName;
ReferenceError:carName = "Volvo";
let carName;
Using a const variable before it is declared, is a syntax errror, so the code will simply not run.
Example
This code will not run.
carName = "Volvo";
const carName;
const carName;
Practice Excercise Practice now