我可以简化这个使用逻辑非运算符的条件语句吗?

发布于 2024-09-08 01:23:29 字数 422 浏览 3 评论 0原文

抱歉,如果这是“逻辑运算符 101”之类的问题。我已经盯着屏幕看了 15 分钟,试图集中注意力,但我被困住了。

是否有更简洁/优雅的方式来表达以下内容(这是 JavaScript 语法,但它不是依赖于语言的问题):

if (!something && !something_else) {
  // do something
}

基于一些实验,这似乎不是逻辑上的等价物:

if (!(something && something_else) {
  // do something
}

此外,任何人都可以推荐一个用于进一步研究此类问题的在线资源?我假设计算机科学课程中抽象地涵盖了此类内容,这是我的编程知识中的一个重要空白,我真的很想填补。谢谢!

Sorry if this is a "Logical Operators 101" kind of question. I've been staring at my screen for 15 minutes trying to wrap my head around it, but I'm stuck.

Is there a more concise/elegant way to phrase the following (this is JavaScript syntax, but it's not a language-dependent question):

if (!something && !something_else) {
  // do something
}

Based on some experimentation, this does not appear to be the logical equivalent:

if (!(something && something_else) {
  // do something
}

In addition, can anyone recommend an online resource(s) for further study on questions like these? I'm assuming that this type of thing is covered on an abstract level in computer science curricula, and it's an essential gap in my programming knowledge that I'd really like to fill. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

花开柳相依 2024-09-15 01:23:29
(Not A) And (Not B)

相当于:

Not (A Or B)

它是德摩根定律的应用

(Not A) And (Not B)

is equivalent to:

Not (A Or B)

It's an application of De Morgan's laws

落日海湾 2024-09-15 01:23:29

正确的表达式应该是:

if (!(something || something else)) {
  // do something
}

当您应用否定时,它会在 AND 和 OR 之间切换运算符。

The proper expression should be:

if (!(something || something else)) {
  // do something
}

When you apply a negation it switches the operators between AND and OR.

生生不灭 2024-09-15 01:23:29

我想,你需要

if (!(something || something_else)) {
  // do something
}

一些东西&& !something_else 的意思是“既不是某物也不是something_else”,相当于“既不是(某物或某物_else)”

I think, you need

if (!(something || something_else)) {
  // do something
}

!something && !something_else means "neither something and neither something_else", which is equivalent to "neither (something or something_else)"

看透却不说透 2024-09-15 01:23:29

您所描述的一个词是“或非门”或“非或门”。

A word for what you are describing is the nor gate, or the not or gate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文