Check if object exist

M

Mateo

Hi!

Let's say that I have generated var SomeVariable = true; from server.
On client side I have:
if (SomeVariable == true) {
do something
}

How could I first check if my variable is undefined? Or how can I say if
some exception occures please don't report error, just continiue?
If variable is not generated from server, it will report me an error....


Thanx guys!
 
R

RobG

Hi!

Let's say that I have generated var SomeVariable = true; from server.
On client side I have:
if (SomeVariable == true) {
do something

}

How could I first check if my variable is undefined?

if (typeof someVariable != 'undefined')
{
// someVariable is not undefined, but
// might be null, or false, or whatever...
}

But if you are expecting it to be boolean true, why not:

if (someVariable) ...
 
M

Mateo

if (typeof someVariable != 'undefined')
{
// someVariable is not undefined, but
// might be null, or false, or whatever...
}


thank u, this works fine....
But if you are expecting it to be boolean true, why not:

this produces error to...
 
M

Mateo

thank you, your solution works fine too... this looks like old browsers
compatibile....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top