JS Built-ins
Variablesintermediate

Variables β€” var hoisting: undefined before declaration

var is hoisted with value undefined

When JavaScript sees a var declaration anywhere in a function, it "hoists" the declaration to the top of the function β€” but not the assignment. Accessing the variable before the assignment returns undefined.

Challenge: Write varHoisting() that:

  1. Captures typeof hoisted before the declaration line
  2. Declares var hoisted = 'later'
  3. Returns the captured typeof result
πŸ’‘ Hints (1)
  • β€’ var is hoisted to the top of the function but without its assigned value