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
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:
- Loading Spinner using CSS.
- CSS box-shadow Property
- Fixed Header Scrolling Table with Bootstrap.
- Element Selectors in CSS
Conclusion:
I hope you understand this tutorial. You can comment for any technical question. Your suggestions and feedback are welcome.
I like what you guys tend to be up too. Such clever work and exposure! Keep up the fantastic works guys I’ve incorporated you guys to blogroll.
Tremendous issues here. I’m very happy to look your article. Thanks a lot and I am having a look ahead to contact you. Will you please drop me a mail?|