Difference between “==” and “===” operator in Javascript

Arivusudar DT
Nov 8 · 1 min read

In this article, I am going to demonstrate the difference between == and === in javascript.

  • If you use == operator in your script. It checks only the value not the datatype. For example

<script>

if(2 == “2”) {

console.log(“both are equal”);

}

else {

console.log(“both are not equal”);

}

</script>

output: both are equal

  • If you use === operator in your script. It checks that datatype and value

<script>

if(2 === “2”) {

console.log(“both are equal”);

}

else {

console.log(“both are not equal”);

}

</script>

output: both are not equal

Conclusion:

Here I explained the difference between == and === using javascript. The == is used to check the value which means it compares the value only and === is used to check the datatype along with the value. It is known as “Strict Comparison”.

Arivusudar DT

Written by

வீழ்வேனென்று நினைத்தாயோ