What is the !! (not not) operator in JavaScript?
Converts Object to boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, true.
!oObject // inverted boolean
!!oObject // non inverted boolean so true boolean
Representation
So !! is not an operator, it's just the !...
blog.pateldeep.xyz1 min read
!!converts the value to the right of it to its equivalent boolean value. (Think poor man's way of "type-casting"). Its intent is usually to convey to the reader that the code does not care what value is in the variable, but what it's "truth" value is. So !! is not an operator, it's just the!operator twice.Real World Example "Test IE version":
const isIE8 = !! navigator.userAgent.match(/MSIE 8.0/); console.log(isIE8); // returns true or falseIf you:
console.log(navigator.userAgent.match(/MSIE 8.0/)); // returns either an Array or nullBut if you:
console.log(!!navigator.userAgent.match(/MSIE 8.0/)); // returns either true or false