什么!!操作员呢?

时间:2013-05-18 03:55:43

标签: javascript

在JavaScript中,'!!'是什么操作员呢? 这不是一个声明吗?

例如:

someFunc(foo) {
    return !! foo;
}
// Return foo only if foo exists?

3 个答案:

答案 0 :(得分:2)

首先,这不是运算符。在javascript

中将其转换为布尔值

实施例

var test = true;

!test = false; //It will converted to false
!!test = true; //Again it will converted to true

答案 1 :(得分:2)

!是“not”运算符,将其一个参数强制转换为布尔值并将其否定。

第二个!否定了它,所以有效!!将值转换为布尔值。

答案 2 :(得分:0)

将foo转换为boolean。

var foo = "TEST";

!foo // Result: false
!!foo // Result: true
相关问题