我可以简化这个使用逻辑非运算符的条件语句吗?
抱歉,如果这是“逻辑运算符 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
相当于:
它是德摩根定律的应用
is equivalent to:
It's an application of De Morgan's laws
正确的表达式应该是:
当您应用否定时,它会在 AND 和 OR 之间切换运算符。
The proper expression should be:
When you apply a negation it switches the operators between AND and OR.
我想,你需要
一些东西&& !something_else 的意思是“既不是某物也不是something_else”,相当于“既不是(某物或某物_else)”
I think, you need
!something && !something_else means "neither something and neither something_else", which is equivalent to "neither (something or something_else)"
您所描述的一个词是“或非门”或“非或门”。
A word for what you are describing is the nor gate, or the not or gate.