Skip to content

Commit 2077eee

Browse files
authored
Add: Equality Comparison
1 parent d5c51ff commit 2077eee

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ One place JavaScript!
1010
- [Splice vs Slice vs Split](#diffs)
1111
- [Data Types](#datatypes)
1212
- [DOM](#dom)
13+
- [Equality comparisons](#eqality)
1314

1415
<a name=“callback”/>
1516

@@ -170,3 +171,41 @@ console.log(h2.className); // Hello
170171
```
171172
Such this, there are many other interface listed below in MDN.
172173
[List of DOM Interface](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model#DOM_interfaces)
174+
175+
<a name=“equality”/>
176+
177+
#### Equality Comparison
178+
179+
JavaScript provides three different value-comparison operations:
180+
1. Strictly equality (===)
181+
182+
triple equals (===) will do the same comparison (including the special handling for NaN, -0, and +0) but without type conversion, by simply always returning false if the types different.
183+
184+
```HTML
185+
Values are not implicitly converted to the some other value. If the values have different types, values are considered differnt.
186+
```
187+
2. Abstract Equality (==)
188+
189+
double equals (==) will perform a type conversion when comparing two things, and will handle NaN, -0, and +0 specially to conform to IEEE 754 (so NaN != NaN, and -0 == +0);
190+
191+
3. Object.is
192+
193+
Object.is does not do type conversion and no special handling for NaN, -0, and +0 (it has the same behavior as === except on those special numeric values).
194+
195+
``` javascript
196+
var a = 0;
197+
var b = new String('0');
198+
var c = '0';
199+
200+
console.log(a === a); // true
201+
console.log(b === b); // true
202+
console.log(c === c); // true
203+
204+
console.log(a === b); // false
205+
console.log(a === c); // false
206+
console.log(b === c); // false
207+
208+
console.log(null === undefined); // false
209+
console.log(obj === null); // false
210+
console.log(obj === undefined); // false
211+
```

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy