ITPub博客

首页 > IT职业 > IT生活 > JavaScript中~~符号什么意思?

JavaScript中~~符号什么意思?

IT生活 作者:fff2001 时间:2021-09-09 10:23:31 0 删除 编辑

是一种利用符号进行的类型转换,转换成数字类型

~~true == 1
~~false == 0
~~"" == 0
~~[] == 0

~~undefined ==0
~~!undefined == 1
~~null == 0
~~!null == 1

~是按位非,就是每一位取反,
~~常用来取整
比如 ~~10.2323=10
~~(10/3) = 3

它被用作一个更快的替代 Math.floor() 。

参考:https://zhidao.baidu.com/question/324495666.html

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3664/viewspace-2821408/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: k8s init-Containers
请登录后发表评论 登录
全部评论

注册时间:2019-08-14

  • 博文量
    74
  • 访问量
    657