Skip to main content

Command Palette

Search for a command to run...

Type coercion confusion in JavaScript

Updated
β€’1 min read
I

π™΅πšžπš•πš• πš‚πšπšŠπšŒπš” π™²πš˜πš™πš’ π™ΏπšŠπšœπšπšŽπš› β„’ | Started in 1984 with LOAD '''' ENTER & PLAY.

Today I learned this is not true in JavaScript, and I'm shocked 🀯

"true" == true //returns false

β€” James Q Quick (@jamesqquick) June 13, 2022

My answer

Yes, when you allow coercion with == you get NaN is not equal to 1.

That is what the spec says.https://t.co/c2rEghMaTq

β€” Ivan BunčiΔ‡ πŸ¦„πŸ₯‘βŒ¨ (@ivanbuncic) June 14, 2022

When you are in doubt, read the Spec please.