Here I am going to explain to you what is the difference between == and === in Javascript. This is mostly asked Interview Question.

Difference Between == and === in Javascript:

JavaScript has the support of both Strict equality and type-converting equality.

  • Strict Equality (===): Strict Equality means the values which have to compare must have the same type. This means:
           3==="3"  //returns false
  • Type-Converting Equality(==): Which convert the values to the same type before performing the comparison.
           3=="3" //returns true

Difference Between == and ===

Example:

<html>
<head>
<title>Difference between == and === in javascript</title>
<script type="text/javascript">
function Diff() {
var value= "3";
if (value == 3)
document.write("== Returns true <br/>")
else
document.write("== Returns false <br/>")
if (value === 3)
document.write("=== Returns true <br/>")
else
document.write("=== Returns false <br/>")
}
</script>
</head>
<body>
<div>
<input type="button" id="btncheck" onclick="Diff()" value="Check Difference" />
</div>
</body>
</html>

View Demo

View More:

Conclusion:

I hope you understand this tutorial. You can comment for any technical question. Your suggestions and feedback are welcome.

Leave a Comment