Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

JavaScript Scope and Hoisting Quiz

Hoisting means declarations are processed before the code runs. var is hoisted and set to undefined, let and const are hoisted but stay uninitialized, and function declarations are hoisted with their body.

These questions also cover block scope, function scope and shadowing.

Scope & Hoisting questions

  1. Is a var loop variable accessible after a for loop?
  2. Why does var in a loop with setTimeout print 3 3 3?
  3. Why does let in a for loop fix the setTimeout closure problem?
  4. Why does using a var before its declaration return undefined?
  5. What is the temporal dead zone in JavaScript?
  6. Can you call a function before it is declared in JavaScript?
  7. Why can't you call a function expression before it's defined?
  8. Does let have block scope in JavaScript?
  9. Does var have block scope in JavaScript?
  10. Why does a var inside a function shadow the outer variable?
  11. What happens when you assign a variable without declaring it?
  12. Why doesn't typeof throw for undeclared variables?
  13. Is a named function expression's name available outside?
  14. What happens when you declare the same function twice?
  15. Are JavaScript classes hoisted?

More topics