JavaScript | ‘===’ vs ‘==’Comparision Operator

In JavaScript, ‘===’ Operator is used to check whether 2 entities are of equal values as well as of equal size and provides a boolean result.
The == operator will compare for equality after doing any necessary type conversions. The === operator will not do any conversion before comparing, so if two values are not of the same type, === will simply return false.

Let us take the case for ‘===’ operator

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<body>
  
<p id="GFG"></p>
  
<script>
var check= 10;
document.getElementById("GFG").innerHTML = (check === 10);
</script>
  
</body>
</html>

chevron_right


Output: true

Explanation:
Since here the value as well as the type of camparing elements matched and the condition is satisfied, hence returns true.
Now let us see another example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<body>
  
<p id="GFG"></p>
  
<script>
var check = 10;
document.getElementById("GFG").innerHTML = (check === "10");
</script>
  
</body>
</html>

chevron_right


Output: false

Explanation:
Since, here the value with which it is being compared have same values but not of same type, hence the condition is not satisfied. And hence it returns false.


Let us take the case for ‘==’ operator
Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<body>
  
<p id="GFG"></p>
  
<script>
var check = 10;
document.getElementById("GFG").innerHTML = (check == "10");
</script>
  
</body>
</html>

chevron_right


Output: True

Since ‘==’ compared for equality after doing any necessary type conversions.
And would result into a false only if the values are not identical.
Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<body>
   
<p id="GFG"></p>
   
<script>
var check= 10;
document.getElementById("GFG").innerHTML = (check === 15);
</script>
   
</body>
</html>

chevron_right


Output: False

As the values are not identical.



My Personal Notes arrow_drop_up

Lets get started

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.