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
x
14
14
1
function equality( number ){
2
if ( number === 7 ){
3
return "it's equal"
4
} else { return "not equal"}
5
}
6
console.log(equality(7))
7
8
function nonEquality( number ){
9
if ( number !== 7 ){
10
return "it's not equal"
11
} else { return "it's equal"}
12
}
13
console.log(nonEquality(7));
14
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
1
2
1
if(i > 4 && i < 10 && i !== 8)
2
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.