Emptiness in Javascript can be complicated...

“Emptiness” in javascript sometimes makes me scratch my head. Especially when checking for emptiness. Think I’m crazy? Ask your fellow developers to explain the difference between null + undefined.

 

What does the MDN say about NULL?

Null: The value null represents the intentional absence of any object value. It is one of JavaScript’s primitive values and is treated as falsy for boolean operations.

 

 

What does the MDN say about Undefined?

Undefined: The global undefined property represents the primitive value undefined. It is one of JavaScript’s primitive types. A variable that has not been assigned a value is of type undefined. A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned.

 

How about a silly… but really easy to understand image. I found this on stack overflow.

Photo by Izz R on Unsplash

Leave a Reply