In Javascript, is it OK to put the ternary operator's `?` on then next line?

后端 未结 4 1356
深忆病人
深忆病人 2021-02-01 15:08

I really like aligning the ? and the : of my ternary operator when they don\'t fit on a line, like this:

var myVar = (condition
    ? ifTrue
    : ifFalse
);
         


        
4条回答
  •  春和景丽
    2021-02-01 15:43

    This works and is certainly valid. It's especially useful in more complicated use cases, like nested ones.

    var a = test1
             ? b
             : test2
                ? c
                : d;
    

提交回复
热议问题