Null: The valuenullrepresents the intentional absence of any object value. It is explicitly set by the programmer to indicate that there is no value. For example:let x = null; console.log(x); // nullUndefined: The valueundefinedis automatically assigned to variables that are declared but not initialized. For example:let x; console.log(x); // undefinedBooleans: TheBooleansdata type is used to represent truth values (trueorfalse). They are typically used in conditions, loops, and other control structures to make decisions in your code. For example:let x = true; let y = false;- Difference between
nullandundefinedWhen checking fornullorundefined, beware of the differences between equality (==) and identity (===) operators (opens in a new tab), as the former performs type-conversion.typeof null; // "object" (not "null" for legacy reasons) typeof undefined; // "undefined" null === undefined; // false null == undefined; // true null === null; // true null == null; // true !null; // true Number.isNaN(1 + null); // false Number.isNaN(1 + undefined); // true