Not-Equal Operator


Comparison Not-Equal

comparison not-equal operator takes two operands, returns true if left and right operands are not equal in value, or false otherwise

!= symbol is used for comparison not-equal operator

a != 5  //returns true if a has not a value of 5
a != b  //returns true if a and b are not same in value

Examples

1. check if value of a is not equal to 5

var a = 7;
if (a != 5) {
    console.log('a is not 5');
} else {
    console.log('a is 5');
}

2. check if values in a and b are not equal to each other

var a = 5;
var b = 5;
if (a != b) {
    console.log('a and b are not equal');
} else {
    console.log('a and b are equal');
}