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

后端 未结 7 1570
情歌与酒
情歌与酒 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:52

    to charlie roberts' answer above, I would add:

    the following link gives some incisive answers; the result for switches in Firefox being the most striking: http://jsperf.com/if-else-vs-arrays-vs-switch-vs-ternary/39

    Those who question why anyone would investigate optimization to this degree would do well to research WebGL!

提交回复
热议问题