Hoisting in JavaScript: avoiding an unwanted undefined
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