Closed yukulele closed 11 years ago
I disagree with the reasoning: in modern JavaScript, undefined
seems to be no longer overwriteable (though writing to it does not cause any exception). The expression void 0
may be shorter than undefined
but that seems like a case of premature optimisation.
Historically, the overwrite-safe idiom was if (typeof a === 'undefined') {/* ... */}
. The problem with void 0
is that it is less readable. In either case you mean "a
is undefined
", but to understand that void 0
evaluates to undefined
you're relying on trivia.
The terseness is why minifiers tend to use it, but their output is not exactly an example of readable code (quite the contrary actually).
+1
(to @pluma's argument)
a fast, short and reliable method to check undefined: