Please can someone explain to me what this line of code does:
var list = calls[ev] || (calls[ev] = {});
My best guess:
It\'s setting t
||
or 'logical OR' has a higher precedence than the assignment operator =
, thus the parentheses are necessary to ensure this idiom evaluates in the right order
The other thing to be aware of is that many languages, Javascript included, provide short-circuit evaluation of boolean operators like AND and OR. If the first operand of a logical-or evaluates true, there is no need to evaluate the second operand, as it would make no difference to the result.
Understand this, and you'll see this isn't some special assignment syntax, but an idiom, or pattern, that exploits a language feature to provide a more compact representation of an idea.