what is the meaning of this line kindly explain?
what is the use of double pipeline operator ?
collection[id][prop] = collection[id][prop] || ;
what is the meaning of this line kindly explain?
what is the use of double pipeline operator ?
collection[id][prop] = collection[id][prop] || ;
It’s a Boolean OR.
If the left side is true, return that, otherwise return the right hand side.
So in this case, it says
collection[id][prop] = collection[id][prop] || [];
If collection[id][prop]
has a value that evaluates to true
, assign that value to it (ie if it has a value, keep it as-is). But if it doesn’t have a truthy value (eg it isn’t defined), assign it an empty array.