Hiprup

What is hoisting in JavaScript?

Hoisting is JavaScript moving declarations to the top of their scope before the code runs. Only declarations are hoisted, not the values assigned to them.

  • var — hoisted and set to undefined, so using it early gives undefined rather than an error.

  • let / const — hoisted but left in the temporal dead zone; accessing them before their line throws a ReferenceError.

  • Function declarations — fully hoisted, so they can be called before they appear.

  • Function expressions & arrows — only the variable is hoisted, so calling them early fails.

JS moves var a declaration to the top (value stays). Function declarations are hoisted entirely (callable before declaration).

Function expressions follow var rules (hoisted as undefined — calling undefined() throws TypeError). let/const are hoisted but in TDZ (ReferenceError if accessed before declaration).

Know what hoists fully (function declarations), what hoists partially (var — undefined), and what hoists but stays in TDZ (let/const/class). The function expression vs declaration hoisting difference is the most tested detail.

What is hoisting in JavaScript? | Hiprup