NaN is one of those vestigial implementations of questionable origins, but for the most part I get it. However, I typed this into a Node prompt today and couldn't really make sense of it...
NaN = !NaN
> true
Is this simply returning the evaluated result of !NaN
? This makes sense, but I'm surprised that there's not an error when attempting to assign NaN to another value.
Note: this question is about this specific syntax structure; there are a lot of questions related to NaN and isNaN out there but I couldn't find an answer after googling. Thanks to Ori Drori for the best answer thus far.
console.log(NaN = !NaN);
You are assigning
true
toNaN
instead of comparingNaN
to!NaN
using===
or==
, so the operation returns the assigned value ->true
. Javascript ignores this assignment silently becauseNaN
is read only.If you'll add
use strict
to your code, JS will throw a read only error instead: