JavaScript oddity: switch(42) with a case of (() => 42)() actually matches and runs

mitsuhiko · x · 2026-11-04

mitsuhiko shared a screenshot of a baffling JavaScript snippet: inside switch (42), the branch case (() => 42)(): console.log("why") is apparently valid and actually matches, printing "why". Yet another head-scratcher from JS's coercion and expression rules.

Original post →

More from Fun

Fun channel →