Best Way for Conditional Variable Assignment

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

    I would prefer 2nd option too, no technical reason but for the sake of easy to read code, readability is very important in code.

    If you see the second option, from processing point of view only one check will ever be executed, saved some very minute processing time, so there is only one check in second case.

提交回复
热议问题