Javascript 如何在Javascript中获取变量的相反布尔值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12772494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 11:13:30 来源:igfitidea点击:
How to get opposite boolean value of variable in Javascript
提问by s.webbandit
var a = true;
How to get opposite value of a
(false) and vice versa?
如何获得a
(false)的相反值,反之亦然?
回答by zetlen
回答by richardaday
>>> a = true;
true
>>> !a;
false
回答by Ahmed Roshdy
This would be much easier
这会容易得多
var b = !a
This would make true a false and false a true
这将使真成为假,假成为真
回答by Dmitriy Apollonin
Try the following:
请尝试以下操作:
var a = !a;
回答by Alcides Queiroz Aguiar
Use the "not" operator
使用“非”运算符
var a = true;
alert(!a); //=>false
回答by Charlie
Something like this, perhaps;
也许是这样的;
function toggleFlag(value){
var toggle = value ? false : true;
return toggle;
}
var a = true;
a = toggleFlag(a);
回答by Ratan Uday Kumar
Try like Below
尝试如下
var Boolify = require('node-boolify').Boolify;
var opp_var = !Boolify(myVar);
Refer node-boolify