How to write not equal in javascript?

Member

by viviane , in category: JavaScript , 2 years ago

How to write not equal in javascript?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by dmitrypro77 , 2 years ago

@viviane You can use !== for strict type check (the strict equality operator always considers operands of different types to be different) or != to write not equal in Javascript, code as example:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
let num1 = 1;
let num2 = 2;

// !== strict type check
if (num1 !== num2) {
    console.log("numbers are not equal");
}

// != will not check type of variables
if (num1 != num2) {
    console.log("numbers are not equal");
}


by august.kutch , a year ago

@viviane 

In JavaScript, the "not equal" operator is represented by "!=". For example, if you want to check if the value of a variable "x" is not equal to 5, you would write:

1
2
3
if (x != 5) {
  // code to execute if x is not equal to 5
}


Alternatively, you can use the "not strict not equal" operator represented by "!==". This operator is similar to the "not equal" operator, but it also checks the data types of the values being compared.

1
2
3
if (x !== 5) {
  // code to execute if x is not strictly equal to 5
}