DEV Community

Discussion on: JavaScript Tip: whatis() — A better typeof

Collapse
 
bbarbour profile image
Brian Barbour • Edited

Undefined is a primitive type in Javascript. Understanding it and what it means is fundamental to the language. I'm very curious, why would you want to avoid returning it?

Collapse
 
gladchinda profile image
Glad Chinda

The primary focus of this post is handling type checking in JavaScript. For a very long time, relying on the typeof operator has been very problematic, especially for null, arrays, undeclared variables, etc.

For example, an undeclared identifier is not the same as a variable that is set to undefined. However, typeof operator reports both as "undefined". So how does one make the distinction? That is the essence of this post.

The technique described in the post is very popular for detailed type checking. However, as mentioned in the post, it is not completely error proof.

Collapse
 
bbarbour profile image
Brian Barbour

Gotcha! Makes sense. Thanks for clarifying.