Javascript check for undefined or null object/variable

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

Based on some comments in [StackOverflow Question]( "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


RSS Icon Subscribe to comments

You need to login to post a comment.