-2

What does || [] mean in the code below? Why might this be needed?

getPair: function() {
    return this.props.pair || [];
  },
Baz
  • 12,713
  • 38
  • 145
  • 268

1 Answers1

3

[] is an empty array. ||, in this context, is a guard operator.

The statement says to return this.props.pair, but if this.props.pair is falsy, an empty array will be returned instead.

David Hedlund
  • 128,221
  • 31
  • 203
  • 222