Skip to content
the poor coder

how to say "and not" in javascript

Poor Man
Published
Reading time
1 min read

How to say "and not" in JavaScript?#

If you want to exclude something from a condition, you can use the "and not" operator. In JavaScript, the "and not" operator is represented by the exclamation mark followed by two equals signs (!==). This operator is used to test for values that are not equal to a specified value.

For example, let's say you want to test if a variable is not equal to the value "hello". You would write:

Text

if (myVar !== "hello") {
  // Do something
}

This code will check if myVar is not equal to "hello", and execute the code inside the curly braces if it is true.

Another way to write the same code is by using the "not" operator (!) and the "equals" operator (==):

Text

if (!(myVar == "hello")) {
  // Do something
}

The above code will also check if myVar is not equal to "hello", and execute the code inside the curly braces if it is true. However, this syntax can be a bit more confusing and harder to read, so it's recommended to use the first syntax.

It's important to note that the "and not" operator only checks if a value is not equal to a specified value. If you want to check if a value is not equal to any of several values, you can use the "or" operator (||) and multiple "not equals" conditions:

Text

if (myVar !== "hello" || myVar !== "world") {
  // Do something
}

The above code will check if myVar is not equal to either "hello" or "world", and execute the code inside the curly braces if it is true.

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