The Wayback Machine - https://web.archive.org/web/20240118172649/https://www.geeksforgeeks.org/not-logical-operator-injavascript/
Open In App
Related Articles

NOT(!) Logical Operator inJavaScript

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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.

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks 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!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 14 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials