Flat Preloader Icon

It's Study Time

Hoisting in JavaScript

Hoisting in JavaScript is the process in which the interpreter moves the declaration of variables, functions or classes to the top of their scope, before the execution of the code.

Hoisting of function is a very useful way to call it even its written after the code like below.

//Hoisted function call
console.log(hoistedMethodCall());

function hoistedMethodCall (){
    console.log("Hoisted method is called even before its declared");
}
//Hoisted variable usage

    console.log(hoistedVariable);

    var hoistedVariable;

    hoistedVariable= 10;

    console.log(hoistedVariable);

//Output
undefined
10
 console.log(undefinedVariable);

//Output

Uncaught ReferenceError: undefinedVariable is not defined

Share this post