null vs undefined (JavaScript)
undefined means a variable has been declared but no value assigned, while null is a value you deliberately set to mean "empty" or "no value". Both represent absence.
JavaScript
JavaScript gives variables undefined automatically — missing function arguments, unset properties, and uninitialized variables are all undefined.
null is something you choose to assign to signal intentional emptiness. With ==, null and undefined are loosely equal, but with === they are not.
Examples
JavaScript
let a;
const b = null;
console.log(a, b);
console.log(a === b);Output:
undefined null
false