什么是 “===”,并且什么它和 “==”
问题描述:
可能重复相差很大:
Javascript === vs == : Does it matter which “equal” operator I use?什么是 “===”,并且什么它和 “==”
什么请问===
平均工作时与jQuery/JavaScript?以及===
和==
之间的区别是什么?
像我得到这个代码
if ($this.val() != '' || ignore_empty === true) {
var result = validateForm($this);
if (result != 'skip') {
if (validateForm($this)) {
$input_container.removeClass('error').addClass('success');
}
else {
$input_container.removeClass('success').addClass('error');
}
}
}
且有===
我只是想了解它做什么和什么区别。 谢谢
答
两者都是等于运营商。但是===
是类型安全的。
== This is the equal operator and returns a boolean true if both the
operands are equal.
=== This is the strict equal operator and only returns a Boolean true
if both the operands are equal and of the SAME TYPE.
例如:
3 == "3" (int == string) results in true
3 === "3" (int === string) results in false
希望这有助于
答
==比较之前将数据转换为一种类型,===如果不同类型的数据返回false。 ===是可取的。
答
宽泛地说,它提供了更严格的比较。
"0" == 0 // true
"0" === 0 // false
例如...
如需进一步信息,我建议以下马格努斯提供的链接。
http://*.com/questions/359494/javascript-vs-does-it-matter-which-equal-operator-i-use –
@MagnusWinter hehe即将发布,但...试过找到“可能重复”的东西 – Holger