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
Your guess is right. This is a common way to declare "default" values for variables in JavaScript.
function foo(bar) {
var bar = bar || 0; //This sets bar to 0 if it's not already set
console.log(bar);
}
The way this works is that in JavaScript, an undefined variable is falsy, meaning that in any boolean comparaison operation, it will evaluate to false
. You can then use the OR operator to combine two values and it will return the first value that evaluates to true
.