javascript运算符
Suppose you have an expression, which gives you a result.
假设您有一个表达式,它给您一个结果。
You want this result to be a boolean. Either true
or false
.
您希望此结果为布尔值。 无论是true
还是false
。
Not a string, 0, an empty string, undefined, NaN or whatever. true
or false
.
不是字符串,0,空字符串,未定义,NaN或其他。 true
false
。
The !!
operator does that.
!!
运营商做到这一点。
And in reality it’s two negation operators one after the other. There’s no !!
operator in JavaScript. But there’s !
.
实际上,这是两个否定运算符。 没有!!
JavaScript中的运算符。 但是有!
。
It first negates the result of the expression, then it negates it again. In this way if you had a non-zero number, a string, an object, an array, or anything that’s truthy, you’ll get true
back.
它首先否定表达式的结果,然后再次否定它。 这样,如果您有一个非零数字,一个字符串,一个对象,一个数组或任何真实的东西,您将得到true
。
Otherwise you’ll get false
.
否则你会得到false
。
翻译自: https://flaviocopes.com/javascript-double-negation-operator/
javascript运算符