- 浏览: 120436 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
Odysseus_110:
terryang 写道lz加上时间也不太合适,刷新太快的话还是 ...
$.getJSON 缓存 -
ll.james:
5楼的,真管用通知公告模块A.通知公告的类型没有实现控制B.通 ...
$.getJSON 缓存 -
zranye:
这样虽然能启动,但是会出现乱码
resin 无法启动 com.caucho.config.LineConfigException: -
酒杯中的大海:
学习了!!!~
struts 文件上传 乱码 -
酒杯中的大海:
牛逼,膜拜~
struts 文件上传 乱码
5.4.1 Equality (==) and Identity (===)
The == and === operators check whether two values are the same, using two different definitions of sameness. Both operators accept operands of any type, and both return true if their operands are the same and false if they are different. The === operator is known as the identity operator, and it checks whether its two operands are "identical" using a strict definition of sameness. The == operator is known as the equality operator; it checks whether its two operands are "equal" using a more relaxed definition of sameness that allows type conversions.
The identity operator is standardized by ECMAScript v3 and implemented in JavaScript 1.3 and later. With the introduction of the identity operator, JavaScript supports = , == , and === operators. Be sure you understand the differences between the assignment, equality, and identity operators, and be careful to use the right one when coding! Although it is tempting to call all three operators "equals," it may help to reduce confusion if you read "gets or is assigned" for = , "is equal to" for == , and "is identical to" for === .
In JavaScript, numbers, strings, and boolean values are compared by value . In this case, two separate values are involved, and the == and === operators check that these two values are identical. This means that two variables are equal or identical only if they contain the same value. For example, two strings are equal only if they each contain exactly the same characters.
On the other hand, objects, arrays, and functions are compared by reference . This means that two variables are equal only if they refer to the same object. Two separate arrays are never equal or identical, even if they contain equal or identical elements. Two variables that contain references to objects, arrays, or functions are equal only if they refer to the same object, array, or function. If you want to test that two distinct objects contain the same properties or that two distinct arrays contain the same elements, you'll have to check the properties or elements individually for equality or identity. (And, if any of the properties or elements are themselves objects or arrays, you'll have to decide how deep you want the comparison to go.)
The following rules are used to determine whether two values are identical according to the === operator:
-
If the two values have different types, they are not identical.
-
If both values are numbers and have the same value, they are identical, unless either or both values are NaN , in which case they are not identical. The NaN value is never identical to any other value, including itself! To check whether a value is NaN , use the global isNaN( ) function.
-
If both values are strings and contain exactly the same characters in the same positions, they are identical. If the strings differ in length or content, they are not identical. Note that in some cases, the Unicode standard allows more than one way to encode the same string. For efficiency, however, JavaScript string comparison compares strictly on a character-by-character basis, and it assumes that all strings have been converted to a "normalized form" before they are compared. See the "String.localeCompare( )" reference page in the core reference section of this book for another way to compare strings.
-
If both values are the boolean value true or both are the boolean value false , they are identical.
-
If both values refer to the same object, array, or function, they are identical. If they refer to different objects (or arrays or functions) they are not identical, even if both objects have identical properties or both arrays have identical elements.
-
If both values are null or both values are undefined , they are identical.
The following rules are used to determine whether two values are equal according to the == operator:
-
If the two values have the same type, test them for identity. If the values are identical, they are equal; if they are not identical, they are not equal.
-
If the two values do not have the same type, they may still be equal. Use the following rules and type conversions to check for equality:
-
If one value is null and the other is undefined , they are equal.
-
If one value is a number and the other is a string, convert the string to a number and try the comparison again, using the converted value.
-
If either value is true , convert it to 1 and try the comparison again. If either value is false , convert it to 0 and try the comparison again.
-
If one value is an object and the other is a number or string, convert the object to a primitive and try the comparison again. An object is converted to a primitive value by either its toString( ) method or its valueOf( ) method. The built-in classes of core JavaScript attempt valueOf( ) conversion before toString( ) conversion, except for the Date class, which performs toString( ) conversion. Objects that are not part of core JavaScript may convert themselves to primitive values in an implementation-defined way.
-
Any other combinations of values are not equal.
-
As an example of testing for equality, consider the comparison:
"1" == true
This expression evaluates to true , indicating that these very different-looking values are in fact equal. The boolean value true is first converted to the number 1, and the comparison is done again. Next, the string "1" is converted to the number 1. Since both numbers are now the same, the comparison returns true .
When the equality operator in JavaScript 1.1 attempted to convert a string to a number and failed, it displayed an error message noting that the string could not be converted, instead of converting the string to NaN and returning false as the result of the comparison. This bug has been fixed in JavaScript 1.2.
5.4.1.1 Equality and inequality in Netscape
The == operator always behaves as described previously, and the != operator always behaves as described in the next section, with one exception. In client-side JavaScript in Netscape 4 and later, when embedded in a <script> tag that explicitly specifies JavaScript 1.2 as its language attribute, the equality operator behaves like the identity operator, and the inequality operator behaves like the non-identity operator. To avoid this incompatibility, never use the language="JavaScript1.2" attribute to embed your client-side JavaScript code. See Section 11.6 , for a complete list of similar JavaScript 1.2 incompatibilities.
5.4.2 Inequality (!=) and Non-Identity (!==)
The != and !== operators test for the exact opposite of the == and === operators. The != inequality operator returns false if two values are equal to each other and returns true otherwise. The !== non-identity operator returns false if two values are identical to each other and returns true otherwise. Note that this operator is standardized by ECMAScript v3 and implemented in JavaScript 1.3 and later.
As we'll see, the ! operator computes the Boolean NOT operation. This makes it easy to remember that != stands for "not equal to" and !== stands for "not identical to." See the previous section for details on how equality and identity are defined for different data types.
发表评论
-
js 控制iframe 自适应高度
2014-06-13 17:30 588<iframe width="300& ... -
PS 积累
2012-08-30 09:26 0ps里面 将图片 resize的热键: mac: cmd+t ... -
js闭包
2012-08-26 11:25 0js闭包:一个函数嵌套在另外一个函数里面 js闭包的 ... -
HTML的一些小积累
2014-06-13 17:20 6341. position:absolute 使用 ... -
js notes
2014-06-14 09:26 6311 array and object definition ... -
javascript 模态窗口
2011-02-13 18:10 1019用jQuery Impromptu调试个模态窗口调到最后ie6 ... -
javascript 权威指南 学习笔记3:javascript 作用域
2011-02-13 18:00 1036var testvar = 'window属性'; var ... -
javascript 权威指南 学习笔记1
2011-02-05 23:32 1208If you attempt to read the v ... -
javascript 权威指南 学习笔记2: Comparison Operators
2011-02-05 23:31 4885Comparison Operators The mo ... -
sssssdfdsgsdgsdgsg
2010-06-03 08:58 0@import fail on IE7 and @i ... -
undefined
2009-10-17 11:33 0var exp = undefined ; if (ty ... -
读取json数据
2009-10-15 17:17 1616最近做的东西想要用js ... -
json 乱码解决办法
2009-06-29 08:38 1271上周在处理json输出值的时候发现输出的都是乱码,和jsp输出 ... -
galio浏览器的毛病
2009-06-25 17:04 947折腾了两天,终于找到原因了,不同浏览器之间的兼容性真是令人头痛 ... -
过滤nextSibling元素
2009-06-22 22:59 1436// Paging list // Written ... -
javascript 常用操作
2008-07-14 09:28 0<a href="vod1.html" ... -
div 横线
2008-06-14 22:36 2475今天写div,想用div写一条横线,但不管怎么调,div都太高 ... -
PS中存储为web格式图片会变大?
2008-06-09 15:56 0今天切图片,不知道为什么,中间的图片的width在ps中是72 ...
相关推荐
在JavaScript中,比较操作符是编程中的基本元素,它们用于检查两个值是否相等或不等。本主题将深入探讨JavaScript中的"=="和"==="这两个等号操作符的区别,以及它们在不同情况下的行为。 首先,让我们理解"=="(双...
CLR提供了可以区分类型的Equality 和Identity能力。 Equality:如果两个对象是相同的类型,并且它们各自带有相同和等值的属性。(They are instances of the same type and if each of the fields in one object ...
大家知道,JavaScript中的==是一种比较复杂运算,它的运算规则很奇怪,很容易让人犯错,从而成为JavaScript中“最糟糕的特性”之一。 在仔细阅读ECMAScript规范的基础上,我画了一张图,我想等你理解了这张图后,会...
attributetype ( 1.1.1.1.1.1 NAME 'meritAttr' DESC 'meritAttr' EQUALITY caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} SINGLE-VALUE ) objectclass ( 1.1.1.2.1.1 NAME 'meritClass'...
### JavaScript in 10 Minutes: Key Insights for Intermediate and Advanced Programmers #### Introduction "JavaScript in 10 Minutes" is a concise guide that aims to provide intermediate to advanced ...
## 赋值和等于(Assignments and Equality) 赋值运算符如 `=` 用于将右边的值赋给左边的变量。比较运算符如 `==` 和 `===` 分别用于比较值是否相等和值及类型是否都相等。 ## JavaScript常用运算符 - **算术运算符...
在JavaScript中判断两个字符串是否相等是编程基础中的重要内容,尤其对于初学者来说,理解字符串相等性的判断方法对于编写有效的代码至关重要。首先,要了解JavaScript提供了两种相等性运算符:“==”和“===”。这...
在JavaScript-Equality-Game项目中,开发者可以期待学习到: 1. JavaScript中的数据类型,包括基本类型(如字符串、数字、布尔值)和引用类型(如对象)。 2. `==`和`===`运算符的工作原理,以及何时选择使用它们。...
* 属性:attributetype ( 1.3.6.1.4.1.7914.1.2.1.1 NAME 'username' DESC 'name of the user on the mailsystem' EQUALITY caseIgnoreIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-value ) * 类:object...
npm install retext-equality 用 假设我们有以下文件example.txt : He’s pretty set on beating your butt for sheriff. …我们的脚本example.js如下所示: var vfile = require ( 'to-vfile' ) var report = ...
== equality 等同,=== identity 恒等。 ==, 两边值类型不同的时候,要先进行类型转换,再比较。 ==,不做类型转换,类型不同的一定不等。 下面分别说明: 先说 ===,这个比较简单。下面的规则用来判断两个值...
They can be assigned, copied, moved, compared for equality or order, and so on. There are also helper methods Json::dump, to serialize a Json to a string, and Json::parse (static) to parse a std::...
简单的javascript插件,可在页面上创建大小相等的内容 安装 凉亭 bower install equality NPM npm install equalityjs 用法 在您的项目中包含缩小的dist/equality.min.js文件。 告诉平等您想成为平等的人: 它...
Non linear equality and inequality constrained PSO(非线性等式与不等式约束PSO)利用粒子群算法求解非线性等式和不等式约束的最小值。包括matlab完整代码。
UnivEq Scala和Scala.JS的更安全的通用等效项。 (零依赖) 创建:2015年2月。 开源:2016年4月。 动机 在Scala中,所有值和对象都具有以下方法: equals(Any): Boolean ==(Any): Boolean ... 这意味着您可以执行无...
8. **Equality/Inequality Operators (等值/不等值运算符)** - **==/** (等于/不等于): 用于比较两个表达式是否相等。 - 示例: `if (i == 42)` 如果 `i` 等于42则条件成立。 - 示例: `if (i != 42)` 如果 `i` 不...
3. 在JSP页面中引用Tomahawk组件: ```jsp <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %> ``` #### 四、示例组件介绍 ##### 4.1 Date Input - **组件名称**:`<t:dateInput>` - **功能...