In this post, I am
going to share the very interesting double equals "==" and triple equals "===". It is very confusing topic and most of the time peoples are confused.
The details example as given below.
The details example as given below.
The double equals (==) are used for check only value of its variables but triple equals (===) are used for check value and type as well of its variables.
2. The triple equal “===” is
not auto-type conversion and it check value and type both.
For example,
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Difference between == and === in JavaScript</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script> <script> // alert(0 == false); // return true, because both are same type. // alert(0 === false); // return false, because both are of a different type. // alert(1 == "1"); // return true, automatic type conversion for value only. // alert(1 === "1"); // return false, because both are of a different type. // alert(null == undefined); // return true. // alert(null === undefined); // return false. //alert('0' == false); // return true. // alert('0' === false); // return false. // alert(1=== parseInt("1")); // return true. console.log(0 == false); // return true, because both are same type. console.log(0 === false); // return false, because both are of a different type. console.log(1 == "1"); // return true, automatic type conversion for value only. console.log(1 === "1"); // return false, because both are of a different type. console.log(null == undefined); // return true. console.log(null === undefined); // return false. console.log('0' == false); // return true. console.log('0' === false); // return false. console.log(1 === parseInt("1")); // return true. </script> </head> <body> <h3>Difference between == and === in JavaScript</h3> </body> </html>
Example and Result as below