Skip to content

OutputNot attempted

typeof on var, let, function

console.log(typeof a, typeof b, typeof c);
var a = 1;
let b = 2;
function c() {}
console.log(typeof d);

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.

typeof b throws ReferenceError because b is in the TDZ, so nothing prints. TDZ applies in sloppy AND strict mode. TDZ is the only case where typeof on a bare name throws; typeof an undeclared name (d) is safe and gives "undefined".