...

View Full Version : var test =a||b;



otnj2ee
10-04-2008, 12:39 AM
I often saw a variable assignment like this:

var onComplete = onComplete || false;


My understanding: if onComplete is valid, return the value of ocComplete; otherwise, return false.

--Is this correct understanding?

--If so, how to determine if the onComplete is valid or not? Use onComplete ==null or else?


Thanks


Scott

oesxyl
10-04-2008, 12:55 AM
--If so, how to determine if the onComplete is valid or not? Use onComplete ==null or else?

|| operator:

http://www.javascriptkit.com/jsref/comparison_operators.shtml



If the first expression does NOT evaluate to true (ie: it's null or undefined), then the value of the second expression is evaluated and returned.


best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum