Possible Duplicate:
What does “options = options || {}” mean in Javascript?
I stumbled upon this line, and can’t seem to figure out what it means
var G = G || {};
Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If
Gis currently any “falsey” value, then the object literal will be assigned toG.The “falsey” values are…
undefinednull''NaNfalse0The operator being used is the logical OR operator.
The way it works is that it evaluates its left operand first. If that operand has a “truthy” value (any non-falsey value), it returns it, and doesn’t evaluate (short-circuits) the second operand.
If the left operand was “falsey”, then it returns its right operand, irrespective of its value.
Example where
Gis falsey…Example where
Gis truthy…