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?
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.
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?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 fornull
, 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.
Gotcha! Makes sense. Thanks for clarifying.