Posted By

EvanHahn on 03/12/12


Tagged

undefined


Versions (?)

Is something undefined in JavaScript?


 / Published in: JavaScript
 

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 type-checking library.

  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  

You need to login to post a comment.