if(!! condition)和if(condition)之间有什么区别 [英] What is the difference between if(!!condition) and if(condition)

查看:694
本文介绍了if(!! condition)和if(condition)之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常看到使用 !! condition 的代码而不是常规条件。即:

I often see code that uses !!condition as opposed to just the regular condition. I.e.:

if(!!value){
    doSomething();
}

与:

if(value){
    doSomething();
}

如果存在功能上的差异是什么?一个优于另一个?如果有的话,选择使用一个与另一个的条件是什么?

What is the funcational difference, if there is one? Is one superior to the other? What, if any, are the conditions for picking to use one versus the other?

推荐答案

技术上没什么。双重爆炸 !! 类型将转换为布尔值 - 这是if语句在计算<$ c $时所做的事情c>值无论如何。

Technically nothing. The double bang !! type converts value to a boolean - something the if statement does when it evaluates value anyway.

在您发布的代码中, !! 没用,没有任何目的。

In the code you have posted, the !! is useless and serves no purpose.

这篇关于if(!! condition)和if(condition)之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆