-1

Simple question but i'm stuck for a while on it.

I need to check if a var is defined, before execute some taks.

So i try this

if (myVar !== null) alert('myVar is not null');

But when i do this and myVar is not defined, an exception is threw :

Uncaught ReferenceError: myVar is not defined at :1:1

So how to solve this dilema ?

delphirules
  • 5,815
  • 14
  • 51
  • 95

1 Answers1

1

You can use type of

if (typeof variable !== 'undefined') alert('myVar is not null');
Andam
  • 1,817
  • 1
  • 6
  • 19