Last updated: September 18, 2021.
undefined is used to signify that a variable has been initialised but no value has yet been assigned to it. For example:
let emptyVariable; alert(emptyVariable); // undefined alert(typeof emptyVariable); // undefined
varto initialize a variable with no assigned value. This is not allowed with
null on the other hand is an assigned value that indicates no value:
let nullVariable= null; alert( nullVariable ); // null alert(typeof nullVariable ); // object
You may be surprised null is of the type
object and not type
null given that it is a primitive object.