Triple (3) Equal Signs [duplicate]
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.
Triple equal sign in javascript means equality without type coercion.
For example:
1=="1" // true, automatic type coersion
1==="1" // false, not the same type.
Three equal signs indicates both the value and type are equal.