A logical NOT operator !
(逻辑NOT运算符!
)
converts a value to a boolean that is the opposite of its logical value.(将值转换为与其逻辑值相反的布尔值。)
The second !
(第二个!
)
converts the previous boolean result back to the boolean representation of its original logical value.(将前一个布尔结果转换回其原始逻辑值的布尔表示。)
From these docs for the Logical NOT operator:
(从 Logical NOT运算符的这些文档中:)
Returns false if its single operand can be converted to true;
(如果单个操作数可以转换为true,则返回false;)
otherwise, returns true.(否则,返回true。)
So if getContext
gives you a "falsey" value, the !!
(所以如果getContext
给你一个“假”值,那就!!
)
will make it return the boolean value false
.(将使它返回布尔值false
。)
Otherwise it will return true
.(否则它将返回true
。)
The "falsey" values are:
(“假”值是:)
-
false
-
NaN
-
undefined
-
null
-
""
(empty string)(""
(空字符串))
-
0
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…