Not-equal-value or Not-equal-type Operator


Comparison Not-equal-value or Not-equal-type

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

!== symbol is used for comparison not-equal-value or not-equal-type operator

a !== 5  //returns true if a is not 5 or not numeric
a !== b

since not-equal-value and not-equal-type operator does check either type or value, the following example illustrates the case

a = 5     //a has a value of 5 (numeric)
a !== '5' //returns true
a !== 4   //returns true
a !== 5   //returns false

Examples

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

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

2. check if values in a and b are not equal to each other either in value or type

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

3. check if value in a is not equal to 5 in value, or not numeric

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

a is assigned with a string type value. since comparison not-equal-value and not-equal-type operator checks both the type and value, a !== 5 returns true