I think the above example would be enough to clear this difference.
As you can see, I have defined two variables num1 and num2 but note that num1 is assigned with "1" (String) and num2 is assigned with 1 (Number).
Then, I have put log statements with those operators. And you can see in the output that == operator gives true and === operator gives false as output.
Let me explain why this output produced because, == operator always compares values of given operands. It will not check the types of the given operands. Whereas, === operator always compares values plus type of the given operands. Here in our example "1" and 1, both are equals in terms of values but they are of different types.
Which one should you use?
- The answer can be varied from different perspectives. In my opinion, if you can you should use === operator. Because it will give you more control then == operator.
I hope you liked it and let me know your thought on this topic by commenting down below.
Follow me on twitter: https://twitter.com/ykhokhaneshiya