Coerces oObject
to boolean.
(将oObject oObject
为布尔值。)
If it was falsey (eg 0, null
, undefined
, etc.), it will be false
, otherwise, true
.(如果它为假(例如0, null
, undefined
等),则为false
,否则为true
。)
!oObject //Inverted boolean
!!oObject //Non inverted boolean so true boolean representation
So !!
(所以!!
)
is not an operator, it's just the !
(不是运算符,而只是!
)
operator twice.(操作员两次。)
Real World Example "Test IE version":
(真实示例“测试IE版本”:)
let isIE8 = false;
isIE8 = !! navigator.userAgent.match(/MSIE 8.0/);
console.log(isIE8); // returns true or false
If you ?
(如果你?)
console.log(navigator.userAgent.match(/MSIE 8.0/));
// returns either an Array or null
but if you ?
(但是如果你?)
console.log(!!navigator.userAgent.match(/MSIE 8.0/));
// returns either true or false
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…