🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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);
  1. A.number number
  2. B.number undefined
  3. C.undefined undefined
  4. 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 →