← Quiz: Scope, Closures, Hoisting and this: all 15 questions
Quiz: Scope, Closures, Hoisting and this · Question 11 of 15
What does this print? (code)
What does this print?
if (true) {
var a = 1;
let b = 2;
}
console.log(typeof a, typeof b);
- A.number number
- B.number undefined
- C.undefined undefined
- D.It throws a ReferenceError
Answer & explanation
Correct answer: number undefined
var ignores the block, so a is visible outside; b is block-scoped, and typeof of an undeclared name gives "undefined".
Can you get the rest right without peeking?
Take the timed Quiz: Scope, Closures, Hoisting and this quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →