Learn JavaScript

Lesson 2 of 9 · Scope, Hoisting and Closures

Module 6 · Scope, Hoisting and Closures

Every Rule, One by One: Blocks, var, Hoisting and the Dead Zone

Free with an accountReading

Bob's shop program prints notebook costs undefined. He set the price to 450 on line 9, and line 3 printed it. No error stopped him, because he declared the price with var, and var makes reading a name early legal. Module 1 promised to explain this, and the hoisting section below does.

Checking what this lesson needs for you…

What is inside Every Rule, One by One: Blocks, var, Hoisting and the Dead Zone

  1. The file's scope and the global object
  2. Block scope: let and const stay in their braces
  3. Function scope: var ignores blocks
  4. Parameters: the function's own names
  5. Shadowing: an inner name hides an outer one
  6. The scope chain and "is not defined"
  7. Hoisting: two passes over every scope
  8. The temporal dead zone
  9. Function expressions and arrows hoist as their variable
  10. A for loop's let: a fresh binding on every pass
  11. The IIFE: a scope made by hand