null vs undefined
Similarities
Both are primitives
Both are falsy:
Differences
undefinedmeans that a variable has not been declared, or it has been declared but has not yet been assigned a value.nullis an assignment value that means “no value”. Javascript itself never sets a value tonullDifference in
typeof:undefinedis not a valid JSON whilenullis.
Tips
Check if a variable is
null:
Check if a variable is
undefined:
Comparison (Equality returns
trueand identity returnsfalse) :
Last updated