Hoisting Basically when we run JavaScript code than it's do every global variable and function go in the top. its called hoisting.
*Variable hoisting: *
console.log(x); // undefined
var x = 5;
console.log(x); // 5
*Functional Hoisting: *
sayHello();
function sayHello() {
console.log("Hello, World!");
}
Note:
var and let/const declarations. let and const are block-scoped and are hoisted but not initialized until their actual declaration in the code, resulting in a "temporal dead zone" if you try to access them before the declaration.
Like
console.log(a);
let a = 10;
Show This error: VM156:1 Uncaught ReferenceError: a is not defined at :1:13
Top comments (0)