素衣清颜淡若尘

js !!,js两个感叹号的用法

电脑版发表于:2020/7/2 16:14


可以为了巧妙的实现为空验证,比较简洁的实现

可以直接判断if(a!=null&&typeof(a)!=undefined&&a!='')

使用

if(!!a)即可


为什么可以这样实现呢

因为一个感叹号的时候,可以让null,underfied,''都为true,所以在取一个反就是false了


!null=true

!undefined=true

!''=true

!100=false

!'abc'=false


关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢