“!= true"之间的区别和"== false"? [英] Difference between "!= true" and "== false"?
问题描述
在编程语言中,比较!= true"和"== false"之间是否存在技术/逻辑差异,如果存在,应在什么情况下选择哪个比较?
Are there any technical/logical differences between the comparison "!= true" and "== false" in programming languages, and if there are, which comparison should be chosen on what occasion?
推荐答案
逻辑上,根据所比较的值的类型和所使用的语言,可能会有差异.例如:
Logically there can be differences depending on the type of value that you are comparing and language you are using. For example:
x == false
表示x != true
,但x != true
并不总是表示x == false
,因为x也可以是一些无意义的值.
x == false
implies x != true
, but x != true
does not always imply x == false
because x can also be some nonsense value.
1 + 1 = 3
都是== false
和!= true
.
7 > cat
都不是== false
和!= true
,因为它是无意义的.
7 > cat
is neither == false
and != true
since it is nonsense.
x = null
是!= true
,但不是== false
.
这篇关于“!= true"之间的区别和"== false"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!