In JavaScript (pre ECMAScript 5 ), undefined not a constant, but a global variable, and therefore you can change its value. Therefore, it would be more reliable to use the typeof operator to check for undefined :
if (typeof _var === 'undefined') { }
In addition, your expression will return a ReferenceError if the _var variable is not declared. However, you can still verify it using the typeof operator, as shown above.
Therefore, you can use the following:
if (typeof _var === 'undefined' || _var === null) { }
Daniel Vassallo
source share