Explain hoisting in JavaScript.

Hoisting moves variable and function declarations to the top of their scope.

console.log(foo); // undefined due to hoisting
var foo = "bar";