Best Way for Conditional Variable Assignment

后端 未结 12 1112
一个人的身影
一个人的身影 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:37

    Another cool thing is that you can do multiple assignment based on a conditional:

    let [long_str, short_str] = a.length > b.length ? [a, b] : [b, a]
    

提交回复
热议问题