``=`=='operators'===`是什么区别? (单,双重和三重平等)

发布于 2025-01-18 16:53:45 字数 290 浏览 1 评论 0 原文

我编写了一些代码,在某些地方需要 == ,而在其他地方则需要 = 。有人可以解释这些差异或为我指明资源的方向吗?

示例:

if($("#block").css.display == "none"){
  $("#block").css.display = "block";
}

我唯一能想到的是,在一个中我正在更改,在另一个中我正在检查。但在两者中我指的是平等。

I have written some code and in certain places == is required and in others = is required. Can someone explain the differences or point me in the direction of the resource that can?

Example:

if($("#block").css.display == "none"){
  $("#block").css.display = "block";
}

The only thing I can come up with is that in one I’m changing and in the other I’m checking. But in both I am referring to equality.

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

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

发布评论

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

评论(5

千寻… 2025-01-25 16:53:45

= 是分配操作员。它将变量(左侧)设置为一个值(右侧)。结果是右侧的值。

== 是比较操作员。它只会返回 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 return true 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 return true 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.

身边 2025-01-25 16:53:45

= 将值分配给变量

== 检查两个参数是否相等

================ 检查两个参数是否等于彼此如果它们的类型相同


不是操作员

!= 检查两个参数是否不相等

> !== 检查两个参数是否彼此不等于该类型不是相同的


> 检查一个参数是否大于一个参数另一个

参数是否大于或等于另一个

> == 不存在


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 same


one more

> checks if one parameter is greater than the other

>= checks if one parameter is greater than or equal to the other

>== DOESN'T EXIST


etcetera...

糖粟与秋泊 2025-01-25 16:53:45

==用于测试左侧的值是否等于右侧的值。

=用于将右侧的值分配给左侧的变量。

== 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.

眼眸 2025-01-25 16:53:45

在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.

老子叫无熙 2025-01-25 16:53:45

= 运算符是赋值运算符。您正在将一个对象分配给一个值。 == 运算符是条件相等运算。您正在确认两个事物是否具有相同的值。还有一个 === 运算符。这不仅比较值,还比较类型。

赋值运算符

比较运算符

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

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