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.
More from Fun
- Dev's "killing myself today" quip captures vibe-coding burnout humor — jaivin · 2026-11-04
- ML researcher jokes: 'I'm good at ML because I found attention is all I need early' — michellechen · 2026-11-04
- AI-and-fiction book gets its first negative review from a literary critic — _akpiper · 2026-11-04
- Great idea? It's already been built 117 times on Product Hunt in the last 10 seconds — Dan_Jeffries1 · 2026-11-04
- AI vs bureaucracy will be bloody: 30-minute work sitting in a 7-day queue — airkatakana · 2026-11-04
- NFS Most Wanted nostalgia: Blacklist #14 Taz resurfaces after all these years — CatAstro_Piyush · 2026-11-04