在javascript == vs =? [英] In javascript == vs =?
问题描述
很抱歉,如果发布的帖子太多,但是搜索字段希望重新定义"=,因此很难搜索== javascript" == javascript等.
Sorry if this is posted a ton but search fields like to repurpose "=" so it's very hard to search for == javascript "== javascript" etc.
但是我正在编写一些代码,在某些地方==是必需的,而在其他地方=是必需的.有人可以解释这些差异或将我指向可以提供资源的方向吗?
But I have some code I'm writing 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?
示例:
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.
推荐答案
=
是赋值运算符.它将变量(左侧)设置为值(右侧).
=
is the assignment operator. It sets a variable (the left hand side) to a value (the right hand side).
==
是比较运算符.无论操作数的类型如何,它都会告诉您两个值是否相等.
==
is the comparison operator. It will tell you whether or not two values are equivalent regardless of the type of the operands.
===
是更严格的比较运算符,通常称为身份运算符.仅当操作数的类型和值相同时才返回true.
===
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.
我会结帐: http://www.codecademy.com/tracks/javascript javascript简介.
I would checkout: http://www.codecademy.com/tracks/javascript for a quick intro to javascript.
如果您喜欢阅读: https://developer.mozilla.org/zh-CN/docs/JavaScript/Guide 也是一个很好的介绍.
If you prefer to read: https://developer.mozilla.org/en-US/docs/JavaScript/Guide is a great intro as well.
对于那些关心身份运算符"一词的来源的人,jbabey指出 JavaScript:权威指南似乎是源.
For those concerned about the source of the term "identity operator" jbabey pointed out that JavaScript: The Definitive Guide seems to be a source.
这篇关于在javascript == vs =?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!