A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/not-logical-operator-injavascript/ below:

NOT(!) Logical Operator inJavaScript - GeeksforGeeks

NOT(!) Logical Operator inJavaScript

Last Updated : 14 Mar, 2023

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:

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



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4