我可以使用链式比较运算符语法吗? [英] Can I use chained comparison operator syntax?
本文介绍了我可以使用链式比较运算符语法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个JS库中,我看到了这样的语法:
In one JS library I saw such syntax:
if (val > 5 == t) { ... }
我在控制台中对此进行了测试:
I tested this in console:
1 == 1 == 2 // false
2 > 1 == 1 // true
1 == 2 == 1 // false
1 == 1 == 1 // true
1 < 2 < 3 // true
1 > 2 > 3 // false
乍看之下一切正确.可以使用吗?
At first glance all correct. Can this be used?
推荐答案
1 == 1 == 2 // this
true == 2 // becomes this
1 == 2 // which becomes this, and is false
2 > 1 == 1 // this
true == 1 // becomes this
1 == 1 // which becomes this, and is true
...等等.
如果您想了解转换,您应该在==
运算符上进行搜索,该运算符使用
If you're wondering about the conversion, you should do a search on the ==
operator, which uses the Abstract Equality Comparison Algorithm.
这篇关于我可以使用链式比较运算符语法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文