What is the difference between null and undefined?
Answer
Both represent the absence of a value but differ in intent and origin. undefined means a variable has been declared but not yet assigned a value — it is the default value JavaScript gives to uninitialized variables, missing function parameters, and functions that do not explicitly return. It signals "value not yet set." null is an intentional assignment meaning "no value" — a developer explicitly sets it to indicate the absence of a value. Use it to signal "this value exists but is intentionally empty." Typeof difference: typeof undefined === "undefined" but typeof null === "object" (a historical bug). In loose equality: null == undefined is true, but null === undefined is false. Best practice: return null from functions to indicate "intentionally no result"; let variables default to undefined.