Pranam Bhat
What is hoisting in JavaScript? Explain with an example.

What is hoisting in JavaScript? Explain with an example.

By Pranam Bhat in JavaScript on Aug 11 2021
  • Ganesan C
    Aug, 2021 12

    Hoisting is the default behavior of moving all the declarations at the top of the scope before code execution. In JavaScript, all variable which are declared with ‘var’ and functions are moved on top of the scope.
    But variable declared with let, const and functions expression are won’t.

    var a;
    console.log(a); //print undefined, beacuse of hoisting.

    a=5;
    console.log(a); //print 5.

    let b;
    console.log(b); //reference error, beacuse of hoisting.

    • 1


Most Popular Job Functions


MOST LIKED QUESTIONS