Advertisement
728x90
The double exclamation or negation(!!) ensures the resulting type is a boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, it will be true.
For example, you can test IE version using this expression as below,
javascript
1let isIE8 = false;
2
3isIE8 = !!navigator.userAgent.match(/MSIE 8.0/);
4
5console.log(isIE8); // returns true or falseIf you don't use this expression then it returns the original value.
javascript
1console.log(navigator.userAgent.match(/MSIE 8.0/)); // returns either an Array or nullNote: The expression !! is not an operator, but it is just twice of ! operator.
Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 71
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
70of476