DEV Community

Sathish K
Sathish K

Posted on

Hoisted and Not Hoisted

What is a hoisted ?
Hoisted is the declaration of variables and function are move the top of the global scope in during the runtime.
The hoisted is help the program the code was executes the function call before.

    myFunction(); // Output: Hello from myFunction!
    function myFunction() {
      console.log("Hello from myFunction!");
    }
Enter fullscreen mode Exit fullscreen mode

What is a not hoisted ?

The Not hoisted is the code executed top of the block is not initialized.
Then access the code in before is declaration function result is Error

console.log(a); // ❌ ReferenceError
let a = 5;

Enter fullscreen mode Exit fullscreen mode

Top comments (0)