I want to know what the difference is between null
and undefined
in JavaScript.
In addition to a different meaning there are other differences:
const { a = "default" } = { a: undefined }; // a is "default"
const { b = "default" } = { b: null }; // b is null
null
but omits undefined
const json = JSON.stringify({ undefinedValue: undefined, nullValue: null });
console.log(json); // prints {"nullValue":null}
console.log(typeof undefined); // "undefined"
console.log(typeof null); // "object" instead of "null"