JavaScriptQuestion 04 of 36
What is hoisting?
Answer out loud or in your head first, then compare.
Answer
Hoisting means declarations are processed before the code runs.
JavaScript
console.log(x);
var x = 10;logs:
undefinedYou can think of it as:
JavaScript
var x;
console.log(x);
x = 10;With let and const:
JavaScript
console.log(x);
let x = 10;you get a ReferenceError.
Before their declaration, let and const variables are in the Temporal Dead Zone.
A function declaration is hoisted too:
JavaScript
hello();
function hello() {
console.log("Hello");
}this works.
How did it go? Be honest — “Not yet” puts the question on your review list.