[英]Why does JavaScript's “in” operator return false incorrectly?
You're able to replicate by so: 您可以这样复制:
var test = {'var1': 'bacon'};
"var1" in test; // Returns true - Correct
!"var1" in test; // Returns false - Correct
"nonexistant" in test; // Returns false - Correct
!"nonexistant" in test; // Returns false - Incorrect - This should be true.. should it not?
The in
operator binds fairly loosely. in
运算符的绑定相当宽松。 It's generally a good idea to parenthesize in
subexpressions. 通常in
子表达式in
加上括号是个好主意。
Thus, !"var1" in test
is parsed as (!"var1") in test
for example. 因此,例如(!"var1") in test
解析为!"var1" in test
中的(!"var1") in test
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.