Javascript 三 (3) 个等号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11234575/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 05:02:06  来源:igfitidea点击:

Triple (3) Equal Signs

javascriptjquery

提问by FastTrack

Possible Duplicate:
JavaScript === vs == : Does it matter which “equal” operator I use?

可能的重复:
JavaScript === vs == :我使用哪个“相等”运算符重要吗?

I asked another questionhere and received a great answer as follows:

我在这里问了另一个问题,得到了一个很好的答案,如下所示:

$(document).on("keydown", function (e) {
  if (e.which === 8 && !$(e.target).is("input, textarea") || $(e.target).is('[readonly]')) {
      e.preventDefault();
  }
}); 

Notice the three equal signs ===in the if-statement. I have always thought you only needed two equal signs ==for a javascript/jQuery if-statement. Is there any reason for the three?

注意===if 语句中的三个等号。我一直认为==javascript/jQuery if 语句只需要两个等号。这三个有什么原因吗?

UPDATE

更新

Sorry for the duplicate question - I searched but didn't find any good questions. I guess I was using the wrong search terms.

很抱歉重复的问题 - 我搜索过但没有找到任何好的问题。我想我使用了错误的搜索词。

回答by Jeshurun

Triple equal sign in javascript means equality without type coercion.

javascript 中的三个等号表示没有类型强制的相等

For example:

例如:

1=="1"     // true, automatic type coersion
1==="1"    // false, not the same type.

回答by Justin

Three equal signs indicates both the value and type are equal.

三个等号表示值和类型都相等。