Skip to content
the poor coder

not equal to in js

Poor Man
Published
Reading time
1 min read
On this page

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:#

Text

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:#

Text

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.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC