Middle
What are null and undefined, and what is the difference? What will typeof null return?
sobes.tech AI
Answer from AI
null and undefined are two different types in JavaScript that denote the absence of a value but are used in different situations:
undefinedmeans that a variable is declared but not assigned a value.nullis an explicit assignment of the value "empty" or "no object".
Difference:
undefinedis the default type for undeclared or uninitialized variables.nullis an object that a programmer can assign to a variable to indicate the absence of a value.
What does typeof null return?
console.log(typeof null); // "object"
This is a historical quirk of JavaScript: null is considered an object, although by its nature it is a primitive representing an empty value.