Javascript — Weird Parts
console.log(NaN === NaN); // false Yes, NaN is not equal to itself. You must use Number.isNaN() instead. This is the gateway drug of JS weirdness.
If you’ve spent more than 48 hours with JavaScript, you’ve probably uttered the phrase: “Wait… why did it do that?” javascript weird parts
const arr = [1, 2, 3]; const obj = { a: 1 }; console.log(arr + arr); // "1,2,31,2,3" (string) console.log(arr + obj); // "1,2,3[object Object]" console
console.log(typeof NaN); // "number" According to the IEEE 754 floating-point spec (which JS uses), NaN is a numeric data type that represents an invalid number. It’s a number that isn’t a number. The weirdness doesn't stop there: console.log(NaN === NaN)
function getObject() { return { value: 42 } } console.log(getObject()); // undefined