Possible Duplicate:
What does “options = options || {}” mean in Javascript?
Looking at the YouTube source...
var yt = yt || {};
Does that mean.. set yt to yt if yt exists, else create a new object?
If that's the case, I didn't think you can put a condition when declaring a variable.
Assign the value of yt back to yt unless it is any of 0, NaN, false, null, "", or undefined (i.e. it's falsy), in which case assign {} to yt.
This works because each of the values in the list above evaluate to false in a boolean expression.
It means exactly that: If the content does not evaluate to false, assign it to itself (which is a neutral operation), otherwise create a new object and assign it to yt. It's typically used to instantiate objects to use as namespaces, first checking if the namespace already exists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With