🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Scope, Closures, Hoisting and this: questions with answers

15 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. What does this print? (code)
  2. Q2. What does this print? (code)
  3. Q3. What does this print? (code)
  4. Q4. What happens when you read a let variable before its declaration line in the same block?
  5. Q5. Why does a for (var i = 0; i < 3; i++) loop with setTimeout print 3 three times?
  6. Q6. Which kind of scope do let and const have, but var does not?
  7. Q7. In which direction does the scope chain look for a variable?
  8. Q8. For a normal (non-arrow) function, what decides the value of this?
  9. Q9. Why does an arrow function used inside a method see the method's this?
  10. Q10. What is a practical use of closures?
  11. Q11. What does this print? (code)
  12. Q12. What does this print? (code)
  13. Q13. What does this print? (code)
  14. Q14. What does this print? (code)
  15. Q15. Which change makes for (var i = 0; i < 3; i++) setTimeout(() = console.log(i)) print 0, 1, 2?