Posted By

zha on 04/10/08


Tagged

javascript variable global


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

joomla


Checking for global variable presence


 / Published in: JavaScript
 

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

/* 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) {

  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) {

Report this snippet  

You need to login to post a comment.