Skip to content
호이스팅기술 정리

Hoisting in JavaScript: avoiding an unwanted undefined

1 min readTech notesMoved from my Tistory blogRead the Korean original

Hoisting: when you declare and initialize a variable, the declaration part gets lifted to the very top.

Hoisting is how the JavaScript interpreter reads code, and you need to understand it to keep an unwanted 'undefined' from being printed.

For example, say you have code like this 👇

js
console.log(x);

var x = 1;

console.log(x);
  • #hoisting
  • #JavaScript hoisting
  • #var

More in Tech notes