-1
this.orientation = this.props.orientation
  ? this.props.orientation == 'horizontal'
    ? 'row'
    : 'column'
  : 'column';

May I know how I interpret this conditional branching? Got this code somewhere else from the web. I did read this https://javascript.info/ifelse#multiple but I still can't understand it.

From my understanding is that this.props.orientation which the orientation is retrieved from the parent. If this.props.orietation == 'horizontal' then return column? Then else if this.props.orientation =='row' then return column?

Marcus
  • 37
  • 7

1 Answers1

1

Inserting parentheses will make things clearer.

this.orientation = this.props.orientation ?
(this.props.orientation == 'horizontal' ? 'row' : 'column') :
'column';

If this.props.orientation is not null or empty, it returns either 'row' or 'column' based on its value compared to "horizontal" ('row' if true, 'column' otherwise). If it is null or empty, it returns 'column' as a default.

Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100
scatter
  • 903
  • 7
  • 24