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

后端 未结 7 1478
情歌与酒
情歌与酒 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.

    0 讨论(0)
提交回复
热议问题