Friday, April 27, 2012

Check defined variable exists or not in Javascript

How to check defined variable exists or not in Javascript :

There are few ways to check if any variable exists or not

1) if(typeof IdOfTheVariable != 'undefined')
     {
             //Do Something
      }

or

2) if(window.IdOfTheVariable === undefined)
    {
        //Do Something
    }


Cheers,

No comments:

Post a Comment