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 »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.