Kibana6.x.x源码分析--JavaScript中 "!~" 这样的符号是啥意思?

看到源码中有一段JS代码不太懂,如下:

里面这个 "!~" 符号看到后有点儿方啊O__O "…,毛线意思?


 【查资料,解释如下】:

indexOf returns -1 when an element cannot be found in an array. Therefore, the if statement is checking if name could not be found in names!~-1 ==> true

indeOf 数组方法在应用时,如果元素不存在于数组内则返回  -1  。因此,申明一个元素不在数组内的,就可以使用语法   !~-1 //true

The tilde (~) operator (bitwise NOT) yields the inverted value (a.k.a. one’s complement) of a.

波浪线 ~ 操作符会按位取反

~-1 === 0. Note that 0 == false and !0 === true

注意到 0 == false 、!0 === true

indexOf returns -1 when an element cannot be found in an array.

当元素不存在数组内时,indexOf 返回 -1 

Therefore, we can use !~-1 === true to find out if indexOf could not find name in names (i.e. returned -1).

因此,元素不存在数组内的话,就可以使用  !~-1 === true 来进行判断

 

参考资料:https://stackoverflow.com/questions/28423512/whats-the-mean-in-javascript?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

转载于:https://www.cnblogs.com/lishidefengchen/p/8778520.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值