javascript中的单加运算符 [英] Single plus operator in javascript
本文介绍了javascript中的单加运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
刚看到下划线的来源:
if (obj.length === +obj.length) {
...
}
加上什么
吗?我以前从未见过这个。
What does the plus
do? I never saw this before.
开发人员认为这是一个好习惯吗?
Is it considered a good practice among developers?
推荐答案
plus将字符串转换为float。您提供的代码等同于以下内容:
The plus converts a string to a float. The code you provided is equivalent to the following:
if ( obj.length === Number(obj.length) ) {
// ...
}
这篇关于javascript中的单加运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文