Javascript check for undefined or null object/variable


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

Based on some comments in [StackOverflow Question](http://stackoverflow.com/questions/95875/javascript-check-to-see-if-a-variable-is-an-object "How to check if a variable is an object")


Copy this code and paste it in your HTML
  1. if(typeof(foo) !== 'undefined' && foo != null) {
  2. //you can use foo!
  3. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.