Test if variable exists


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



Copy this code and paste it in your HTML
  1. var foo = "bar";
  2.  
  3. if ( typeof( window[ 'foo' ] ) != "undefined" ) {
  4. document.write("foo is defined")
  5. } else {
  6. document.write("foo is undefined")
  7. }

URL: http://www.rgagnon.com/jsdetails/js-0112.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.