转换
Object为
boolean。如果是falsey(例如
0,
null,
undefined等),这将是
false,否则,
true。
!oObject // inverted boolean!!oObject // non inverted boolean so true boolean representation
因此
!!,不是运算符,只是
!运算符的两倍。
实际示例“测试IE版本”:
const isIE8 = !! navigator.userAgent.match(/MSIE 8.0/); console.log(isIE8); // returns true or false
如果你⇒
console.log(navigator.userAgent.match(/MSIE 8.0/)); // returns either an Array or null
但是如果你⇒
console.log(!!navigator.userAgent.match(/MSIE 8.0/)); // returns either true or false



