Skip to content
Advertisement

Why use !== when you can use ===?

I could simply vice versa the code to be executed by the if and else. And === is more easier to use compared to !== so why is the not equal operator used?

JavaScript

Advertisement

Answer

You cannot use conditional statements to convert the operators for most common cases. In your example, it would be easy and readable to convert the non-equal operator to equal operator by using if-else. But what if a condition like this?

JavaScript

Do you want to apply converting logic here to replace the non-equal operator? The more you convert, then more complicated and unreadable your code is.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement