Is ternary operator, if-else or logical OR faster in javascript?

后端 未结 7 1621
情歌与酒
情歌与酒 2020-11-30 02:06

Which method is faster or more responsive in javascript, if-else, the ternary operator or logical OR? Which is advisable to use, for what reasons?

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 02:41

    I'm doing another syntax:

    var a = true,
        b;
    
    b = (a == false) 
        ? true // if a == false, b = true
        : false; // else: a == true so b = false
    
        /* Equivalent of
        if(a == true)
          var b = true;
        else
          var b = false;
    

    Some people like my code and tell me it's simple to read.

提交回复
热议问题