``=`=='operators'===`是什么区别? (单,双重和三重平等)
我编写了一些代码,在某些地方需要 ==
,而在其他地方则需要 =
。有人可以解释这些差异或为我指明资源的方向吗?
示例:
if($("#block").css.display == "none"){
$("#block").css.display = "block";
}
我唯一能想到的是,在一个中我正在更改,在另一个中我正在检查。但在两者中我指的是平等。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
=
是分配操作员。它将变量(左侧)设置为一个值(右侧)。结果是右侧的值。==
是比较操作员。它只会返回true
,如果两个值在将其类型施加到同一类型之后都是等效的。===
是一个更严格的比较操作员,通常称为身份操作员。如果操作数的类型和值均相同,则只会返回true
。我会检查 codecademy 以获取JavaScript的快速介绍。
如果您想阅读更多信息, mdn 也是一个很棒的简介。
对于那些担心术语“身份操作员”的来源的人,jbabey指出似乎提到了它。
=
is the assignment operator. It sets a variable (the left-hand side) to a value (the right-hand side). The result is the value on the right-hand side.==
is the comparison operator. It will only returntrue
if both values are equivalent after coercing their types to the same type.===
is a more strict comparison operator often called the identity operator. It will only returntrue
if both the type and value of the operands are the same.I would check out CodeCademy for a quick intro to JavaScript.
If you prefer to read more, MDN is a great intro as well.
For those concerned about the source of the term "identity operator" jbabey pointed out that JavaScript: The Definitive Guide seems to mention it.
=
将值分配给变量==
检查两个参数是否相等================
检查两个参数是否等于彼此和如果它们的类型相同!
不是操作员!=
检查两个参数是否不相等> !==
检查两个参数是否彼此不等于或该类型不是相同的> 检查一个参数是否大于一个参数另一个
参数是否大于或等于另一个
> ==
不存在ETCETERA ...
=
assigns a value to a variable==
checks if the two parameter are equal to each other===
checks if the two parameters are equal to each other and if their type is the same!
not operator!=
checks if the two parameters are not equal to each other!==
checks if the two parameters are not equal to each other or the type is not the sameone more
>
checks if one parameter is greater than the other>=
checks if one parameter is greater than or equal to the other>==
DOESN'T EXISTetcetera...
==用于测试左侧的值是否等于右侧的值。
=用于将右侧的值分配给左侧的变量。
== is used to test if the value on the left is equal to the value on the right.
= is used to assign the value on the right to the variable on the left.
在JavaScript中,您还具有===。
=
这是为变量设置值。==
这是为了比较该值相同。===
这是为了比较该值是否相同,并且类型相同。In javascript you have also the ===.
=
This is for set the value to the variable.==
This is for compare if the value is the same.===
This is for compare if the value is the same and also the type is the same.= 运算符是赋值运算符。您正在将一个对象分配给一个值。 == 运算符是条件相等运算。您正在确认两个事物是否具有相同的值。还有一个 === 运算符。这不仅比较值,还比较类型。
赋值运算符
比较运算符
The = operator is an assignment operator. You are assigning an object to a value. The == operator is a conditional equality operation. You are confirming whether two things have equal values. There is also a === operator. This compares not only value, but also type.
Assignment Operators
Comparison Operators