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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs