Is something undefined in JavaScript?


/ Published in: JavaScript
Save to your folder(s)

Checking for `undefined` in JavaScript is weird (the variable can be redefined), so I made a function to do it. This stuff (and others) is also in my [JSTypes](https://github.com/EvanHahn/JSTypes) type-checking library.


Copy this code and paste it in your HTML
  1. // As a function
  2. Evan.isUndefined = function(u) {
  3. return typeof u === 'undefined';
  4. };
  5.  
  6. // In an "if"
  7. if (typeof foo === 'undefined') {
  8. // ...
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.