Let's say you read some literature that Null is a data type then you run typeof(null) then you find out null is not an object, but it is of type object:
let x = null; console.log(typeof x); // logs "object" //also this not-object-fake-object has no properties let x = null; console.log(x.prop); // TypeError: Cannot read property 'prop' of null
console.log(null < 0); // logs "false" console.log(null > 0); // logs "false" console.log(null == 0); // logs "false" console.log(null === 0); // logs "false" console.log(null <= 0); // logs "true" console.log(null >= 0); // logs "true"
Talking about weird things here is another example NaN is never equal to NaN the best way to test NaN is to use isNaN();
NaN === NaN; //false console.log(isNaN(NaN)); // true console.log(isNaN(123)); // false console.log(isNaN('hello')); // true //But beware console.log(isNaN('123')); // false
Top comments (0)