== vs ===

Varun Wadhwa
2 min readMay 7, 2021

Hello guys!!! today's question is what is the difference between the ‘double equals==’ and the ‘triple equals ===’ operators?

In simple words

‘==’ do not check the data type of the variable before comparison. It converts the variable values same type before performing a comparison which is called type coercion.

‘===’ do check the data type of the variable before comparison. It does not convert the variable values to the same type before performing the comparison.

Let’s see this some example

In the above example, I have taken two-variable FOO and BAR. Foo is of String type and Bar is of number type. let’s perform a comparison of them.

console.log(foo == bar )

what do should be the output ??

Output is true.. It returns true because both variables, foo and bar same value even though they have different types: the bar is of type number whereas foo is a string. But since the == operator does type coercion, the result is true.

console.log(foo === bar)

what would be the output?

Output is False.. it returns false because the types of variables are different. if both the variable have the same data type then it would have returned true.

Conclusion

Do not perform loosely comparison when one side is an explicit Boolean type.

To read more about type coercion.

That’s all! I hope you enjoyed this post. Please share and leave your comments below.

--

--