是三元运算符,if-else或逻辑或更快的javascript? [英] Is ternary operator, if-else or logical OR faster in javascript?

查看:108
本文介绍了是三元运算符,if-else或逻辑或更快的javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javascript,if-else,三元运算符或逻辑OR中哪种方法更快或响应更快?哪个是可取的,出于什么原因使用?

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?

推荐答案

速度差异可以忽略不计 - 使用你发现的更易读的。换句话说,我高度怀疑代码中的瓶颈是由于使用了错误的条件结构。

The speed difference will be negligible - use whichever you find to be more readable. In other words I highly doubt that a bottleneck in your code will be due to using the wrong conditional construct.

这篇关于是三元运算符,if-else或逻辑或更快的javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆