What is the !! (not not) operator in JavaScript?

Learn about the !! (not not) operator in JavaScript with examples.
Submitted by Pratishtha Saxena, on May 16, 2022

JavaScript's double not operator is basically double use of (!) operator. This is a logical not operator. (!!) operator converts non-Boolean to Boolean.

As you know, ! operator reverses the logic, i.e., it return false for !true value and true for !false.

Examples of (!) Operator

!false

Output:

true
!true

Output:

false
!1

Output:

false
!0

Output:

true

It gives false for 1, because here 1 means true and 0 means false.

So simply, if we apply one more not operator in front of this, it will become double not and will give the reverse value of (!expression). As seen above, (!false) will give true, but (!!false) will give false.

Example for not not (!!) Operator

!!false

Output:

false
!!true

Output:

true
!!1

Output:

true
!!0

Output:

false

Here, the double negation / double not not (!!) operator calculates the truth value of a value. It returns a Boolean value.

JavaScript Examples »



Related Examples



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.