-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
  • 6,443
  • 17
  • 59
  • 108

1 Answers1

1

You can use type of

if (typeof variable !== 'undefined') alert('myVar is not null');
Andam
  • 2,087
  • 1
  • 8
  • 21