...

View Full Version : if (somevar == undefined) {



subhailc
11-04-2004, 11:17 AM
what's the syntax for "undefined" or NaN?

trying to say


p == undefined ? p = 0 : p+=x;

'if p isn't yet defined, assign a value of 0, otherwise add x's value to the whatever it is at the moment.'

ca_redwards
11-04-2004, 12:04 PM
what's the syntax for "undefined" or NaN?

trying to say


p == undefined ? p = 0 : p+=x;

'if p isn't yet defined, assign a value of 0, otherwise add x's value to the whatever it is at the moment.'

Try...


p=(typeof(p)!='undefined')?p+x:0;

Does this help?

subhailc
11-04-2004, 12:45 PM
hmm i can't get it to work, probably my error rather than anything wrong with your solution, thanks for the reply.

hemebond
11-04-2004, 09:43 PM
Can you not use
p = (p == null) ? 0 : p + x;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum