!! 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);
If you:
console.log(navigator.userAgent.match(/MSIE 8.0/));
But if you:
console.log(!!navigator.userAgent.match(/MSIE 8.0/));
// returns either true or false
!!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