Best Way for Conditional Variable Assignment

后端 未结 12 1111
一个人的身影
一个人的身影 2021-01-31 02:26

Which is the better way for conditional variable assignment?

1st method

 if (true) {
   var myVariable = \'True\';
 } else {
   var myVariable = \'False\         


        
12条回答
  •  情歌与酒
    2021-01-31 02:54

    You could do a ternary, which is a lot shorter (and no darn curly braces):

    var myVariable = (true) ? 'True' : 'False';
    

提交回复
热议问题