javascript 为什么 3 等于 AngularJS ?有什么具体原因吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26753796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
why 3 equals in AngularJS ? Is there any specific reason?
提问by DeepInJava
I have seen many places where angular js uses triple equals sign ===
to compare two elements why not 2 equals==
. I am just wondering is there any specific reason for that ?
我在很多地方看到 angular js 使用三重等号===
来比较两个元素,为什么不是 2 equals ==
。我只是想知道是否有任何具体原因?
回答by Barry
The ===
operator checks value and type while the ==
operator only checks value, simple example
的===
操作者检查值和类型而==
操作者只检查值,简单的例子
1 == "1" -> true
1 === "1" -> false (types are not equal)
Sometimes you want to use this strict comparison, especially when checking a boolean value.
有时您想使用这种严格的比较,尤其是在检查布尔值时。
1 == true -> true
1 === true -> false (types are not equal)