严格的价值比较(小于/大于)

Cas*_*sey 3 javascript syntax

我很确定以下行为不正确(至少在我的脑海中)因为一些真实的疯狂:

var x = 5;
0 < x < 10 // True, and returns true.
0 < x < 2 // False, and returns true.
0 < x < 0 // False, and returns false.
Run Code Online (Sandbox Code Playgroud)

我的方法是,(0 <5)评估为true,(true <2)也评估为true(即1 <2).我用第三个语句对此进行了测试,这似乎证实了我的理论.现在问的问题是:有没有办法让这个"工作"没有大量的额外代码?

小智 10

"......有没有办法让这个'工作'没有大量的额外代码?"

当然,用&&...

(0 < x) && (x < 10)
Run Code Online (Sandbox Code Playgroud)

如果需要,可以删除括号.