三重(3)等号 [英] Triple (3) Equal Signs

查看:109
本文介绍了三重(3)等号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我在这里>另一个问题并收到了一个很好的答复,如下所示:

I asked another question here 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();
  }
}); 

在if语句中注意三个等号===.我一直认为,对于javascript/jQuery if语句,您只需要两个等号==即可.这三个有什么理由吗?

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?

更新

对不起,重复的问题-我进行了搜索,但没有发现任何好的问题.我想我使用了错误的搜索字词.

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

推荐答案

javascript中的三等号意味着没有类型强制的平等.

Triple equal sign in javascript means equality without type coercion.

例如:

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

这篇关于三重(3)等号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆