-2

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

getPair: function() {
    return this.props.pair || [];
  },
Baz
  • 11,687
  • 35
  • 137
  • 244

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
  • 125,403
  • 30
  • 199
  • 217