Learn JavaScript

Lesson 4 of 9 · Scope, Hoisting and Closures

Module 6 · Scope, Hoisting and Closures

When a Closure, When a Class, When a Module

Free with an accountReading

Kenji has just learned closures, and his code review comment says "make everything a closure". His dashboard has 10,000 product rows, and he wants each row to be a counter factory with its own functions. Maria asks the question she always asks: but why not a class? Both of them are partly right. This lesson is about telling the cases apart.

Checking what this lesson needs for you…

What is inside When a Closure, When a Class, When a Module

  1. Kenji's 10,000 counters
  2. One job, three ways
  3. The chart: four homes for a value
  4. The flowchart: three questions
  5. When a closure goes stale
  6. Closures that hold too much
  7. const, let or var