javascript运算符_双重否定运算符是什么! 用JavaScript做?

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运算符

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值