Do you know what will be the output of this code?
JavaScript
var x = 1;
function f() {
console.log(x);
var x = 2;
}
f();
Show answer and explanation
The answer is undefined.
Inside f, var x is hoisted to the top of the function. That local x shadows the global one and is undefined until the assignment runs.