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

后端 未结 7 1631
情歌与酒
情歌与酒 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 03:00

    There is no difference in speed.

    Some prefer the if/else for readability. Personally, I use the ternary operator whenever the logic is trivial enough to understand on one line.

提交回复
热议问题