Day #4 Pro Tip #Javascript
Undefined is not null , Happy Realization….
Published in
1 min readMar 26, 2018
JavaScript uses both
undefined
andnot null
, but they are used in different context.Null
is default value for objects, whileundefined
is for variables and properties. For an object to benull
, it must be defined, otherwise it will beundefined
. The below code depicts this case.The below code throws throws an error, myObject must be defined first before check for null
myObject !== null && typeof myObject !== "undefined" )
// throws an error myObject is not defined
The below code returns false
typeof myObject !== "undefined" && myObject !== null
// return false
Thanks for reading
Stay tuned for more updates !!!