Checking for global variable presence


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

/* if (globalVariable) {

But this wouldn't work. That code is actually checking to see if the defined variable globalVariable has a null value. If the variable has not been defined, that code will cause an error.

Instead, here is the code that will check for the presence of a global variable:
*/
if (window.globalVariable) {


Copy this code and paste it in your HTML
  1. /* if (globalVariable) {
  2.  
  3. But this wouldn't work. That code is actually checking to see if the defined variable globalVariable has a null value. If the variable has not been defined, that code will cause an error.
  4.  
  5. Instead, here is the code that will check for the presence of a global variable:
  6. */
  7. if (window.globalVariable) {

URL: http://www.breakingpar.com/bkp/home.nsf/0/87256B14007C5C6A87256B260052B40B

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.