Javascript Double Not Operator
Learn when we use Javascript Double Not or not not Operator
Published
Javascript Double Not Operator
It converts a nonboolean to an inverted boolean.
For Example, !8 will be false, since 8 is a non-false value in Javascript.
However, If you boolean-inverts that 8 like !!8 then you will get the original value as a boolean which is true.
!8 //false
!!8 //true
More Examples
!!false === false
!!true === true
!!0 === false
!!parseInt("foo") === false // NaN is falsy
!!1 === true
!!-1 === true // -1 is truthy
!!"" === false // empty string is falsy
!!"foo" === true // non-empty string is truthy
!!"false" === true // ...even if it contains a falsy value
!!window.foo === false // undefined is falsy
!!null === false // null is falsy
!!{} === true // an (empty) object is truthy
!![] === true // an (empty) array is truthy; PHP programmers beware!