Javascript Short Term Meaning

What does this js code mean?

this.totals || (this.totals={});

i suppose that.

if(!this.totals) {
  this.totals = {}
}

Is it correct?

+4
source share
1 answer

You are almost 100% correct. When it occurs ||, the first part is calculated, and if it is a true value, it is returned. If this value is falsehood, estimated second part, which in this case sets this.totalsin {}and returns estimate {}.

+8
source

All Articles