DEV Community

Md Abdur Razzak
Md Abdur Razzak

Posted on

1

What is hoisting in javaScript?

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more