Skip to content

OutputNot attempted

var and function with the same name

console.log(typeof foo);
var foo = 1;
function foo() {}
console.log(typeof foo);

Spaces and quote style don’t matter · write a thrown error as TypeError

Ctrl Enter
Show answer & explanation

The expected output comes from actually running the snippet; opening this shows it next to the explanation.

Function declarations win at hoisting time (foo is the function). Then var foo = 1 runs as a plain assignment, so afterwards it is a number.