not equal to in js

What is "not equal to" in JavaScript?

In JavaScript, "not equal to" is a comparison operator used to compare two values to determine if they are not equal. This operator is denoted by the "!=" symbol.

Example:


const number1 = 5;
const number2 = 10;

if (number1 != number2) {
  console.log("The numbers are not equal.");
} else {
  console.log("The numbers are equal.");
}

In the example above, the "!=" operator is used to compare the values of number1 and number2. Since they are not equal, the code will output "The numbers are not equal."

Another way to check for inequality in JavaScript is to use the "!==", which compares not only the value but also the data type of the two values.

Example:


const string1 = "5";
const number3 = 5;

if (string1 !== number3) {
  console.log("The values are not equal.");
} else {
  console.log("The values are equal.");
}

In the example above, the "!=="" operator is used to compare the string value of string1 and the numeric value of number3. Since they are not equal and have different data types, the code will output "The values are not equal."

Overall, understanding the "not equal to" operator in JavaScript is important for writing effective and accurate code.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe