JavaScriptBeginner#scope

What is hoisting?

During compilation declarations are registered before code runs. Function declarations are fully hoisted, var is hoisted and initialised to undefined, while let/const are hoisted but unusable until their declaration line.

Example
greet();            // works
function greet(){ console.log('hi'); }
console.log(x);     // undefined
var x = 5;
console.log(y);     // ReferenceError
let y = 5;

Related Questions

1
JavaScriptIntermediate#closures#functions

What is a closure?

Open
2
JavaScriptBeginner#operators#coercion

Explain == vs ===.

Open
3
JavaScriptBeginner#coercion

What are truthy and falsy values?

Open