let vs var di loop Playground

Gang Kenari’s open house is the loop: every turn sets a setTimeout, and Rizal, Yanti and Jaya open their boxes. With var and with let, which box do they open…

Why it matters

This is JS’s most famous closure gotcha: it shows up in interviews, in event listener loops, in setTimeout. Understanding it means understanding what a binding is, and why let/const replaced var.

The key idea

var shares one binding, let makes a new binding every turn

Common mistakes

Try it in this playground