!1 和 !0 在 Javascript 中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11550681/
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-24 06:16:31  来源:igfitidea点击:

What does !1 and !0 mean in Javascript?

javascript

提问by m_vdbeek

Possible Duplicate:
return !1 in javascript

可能的重复:
在 javascript 中返回 !1

In a JavaScript file I had to read today, there was a line where a variable was declared like a factorial, like this :

在我今天必须阅读的 JavaScript 文件中,有一行声明变量像阶乘一样,如下所示:

var myVariable = !1;

and then something similar was used as parameter in a function like this :

然后类似的东西被用作这样的函数中的参数:

return variable.myFunction(!0);

Can anyone explain me what the exclamation mark means in this context and eventually, why this is generally used for (benefits) ?

谁能解释一下感叹号在这种情况下的含义,并最终解释为什么这通常用于(好处)?

Thank you in advance !

先感谢您 !

回答by Anirudh Ramanathan

The ! is the boolean NOT operator.

这 !是布尔非运算符。

NOT (!): toggles a statement from true to false or from false to true.

NOT (!):将语句从真切换为假或从假切换为真。

!0 = true
!1 = false

Thisis a brilliant introduction to boolean operators and their use in javascript.

是对布尔运算符及其在 javascript 中使用的精彩介绍。