Practical guides, tutorials, and insights from years of building web and desktop applications. Check out code examples you can actually use!
Null and Undefined - Heroes who are equal to none in Javascript
You have used null. You have used undefined. But, have you ever thought about what they mean to the world and to Javascript? The fact is quite simple - we can’t do a null equality check. console.log(1 == null); // false console.log(0 == null); // false console.log(false == null); // false console.log("" == null); // false The same holds for undefined. console.log(1 == undefined); // false console.log(false == undefined); // false But, they measure up to themselves and to each other. console.log(null == null); // true console.log(null == undefined); // true console.log(null === null); // true console.log(null === undefined); // false Practical usage of null and undefined, therefore, follow this pattern - ...