Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 745
FastTrack Avatar asked Jun 27 '12 20:06

FastTrack


People also ask

What does triple === mean?

When using triple equals === in JavaScript, we are testing for strict equality. This means both the type and the value we are comparing have to be the same.

What does 3 equals sign mean?

Equal Sign with 3 Lines The equal sign with three lines means that something is identical or similar to something but not necessarily equal. Thus, a triple equals sign means equivalent. The equivalent is not the same as 'equals'.

What is meaning of === in JavaScript?

The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.

What does == === mean?

The === operator means "is exactly equal to," matching by both value and data type. The == operator means "is equal to," matching by value only.


2 Answers

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. 
like image 59
Jeshurun Avatar answered Sep 27 '22 20:09

Jeshurun


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

like image 32
Justin Avatar answered Sep 27 '22 22:09

Justin