4 ms·
That's the only part of Javascript's ==/=== dichotomy that I like. It maps directly to the way NULL works in SQL. NULL means "I don't know what this is," so two
by raganwald 16y ago
That's the only part of Javascript's ==/=== dichotomy that I like. It maps directly to the way NULL works in SQL. NULL means "I don't know what this is," so two unknown things can't be tested for equality because you don't know what they are. NaN is a similar concept. You tried to make a number, it borked, how can you test one bork against another for equality?
- Groxx 16y agoI hadn't thought of it that way (comparing borks, not sql null); it does make some sense in that light (though then you should be able to compare the same NaN in two variables...). Though that undefined === undefined works, and so does Infinity === Infinity doesn't make as much sense when thought of that way; infinities aren't all equal, and undefined isn't a single kind of value that it makes sense to compare as if it were. And to counteract the sql null viewpoint, (null === null) works. Also: var x = parseInt("a"); x === NaN // false alert(x); // "NaN" doesn't make a whole lot of sense. isNaN() performs the exact same thing that === NaN implies. Especially as: {}.x // undefined {x:undefined}.x // undefined for(prop in {x:undefined}) alert(prop); // displays "x" {}.x === {x:undefined}.x // true Meh. It's a weird language. Not intending to shoot you down; just spilling my brain into a textbox.