Sunday, October 6, 2024
Google search engine
HomeLanguagesJavascriptNOT(!) Logical Operator inJavaScript

NOT(!) Logical Operator inJavaScript

JavaScript NOT Operator can be used to find the flipped value of a boolean. It can be used to convert a true value to a false and vice-versa. This NOT operator can also be used on non-booleans to convert them to the reverse of their actual boolean value. A NOT operator can be used with another NOT operator to get the original value back.

Syntax: 

!a

Return Type: Flipped boolean value.

Example 1: In this example, we will use the NOT operator on some boolean and other data types.

Javascript




console.log(!true);
console.log(!false);
console.log(!"1");
console.log(!"");
console.log(!null);


Output: We can see that the values converted to true are flipped and false is returned and vice versa.

false
true
false
true
true

Example 2: In this example, we will use two NOT operators on the same boolean and other data types.

Javascript




console.log(!!true);
console.log(!!false);   
console.log(!!"1");
console.log(!!"");
console.log(!!null);


Output: When we applied the NOT operator two times we got the original boolean value back.

true
false
true
false
false

Supported Browsers:

  • Chrome
  • Edge
  • Firefox
  • Safari
  • Opera

We have a complete list of JavaScript Logical Operators, to learn about those please go through JavaScript Logical Operator article.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments