标签云

微信群

扫码加入我们

WeChat QR Code

三(3)等号[复制]

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();
  }
}); 

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?

UPDATE

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


I am guessing its checking absolute equality. Meaning, not just equal, but the same

2018年05月23日01分22秒

This other question has a lot of information on the subject (stackoverflow.com/questions/359494/…)

2018年05月24日01分22秒

Stack Overflow's search feature cannot handle characters such as =, unfortunately. But Google does work: google.com/…

2018年05月23日01分22秒

JS true, false and equal in details: gist.github.com/romankierzkowski/9024908

2018年05月24日01分22秒

+1 I think in terms of strongly typed languages - so the second example would throw an error. Still not used to this and been using javascript for a while now

2018年05月23日01分22秒

I started to answer just like that, then figured this had to be a dupe, see this

2018年05月24日01分22秒