Checking for inequality in JavaScript
The operator !=
checks for inequality.
For example, let's check that the variable
test
is not equal to 0
:
let test = 1;
if (test != 0) {
console.log('+++'); // it will work
} else {
console.log('---');
}
Change the variable value:
let test = 0;
if (test != 0) {
console.log('+++');
} else {
console.log('---'); // it will work
}
Check if the variable test
is not equal to 10
.