You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/05-data-types/02-number/article.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -342,7 +342,7 @@ Please note that an empty or a space-only string is treated as `0` in all numeri
342
342
```js run
343
343
alert( Number.isNaN(NaN) ); // true
344
344
alert( Number.isNaN("str" / 2) ); // true
345
-
345
+
346
346
// Note the difference:
347
347
alert( Number.isNaN("str") ); // false, because "str" belongs to the string type, not the number type
348
348
alert( isNaN("str") ); // true, because isNaN converts string "str" into a number and gets NaN as a result of this conversion
@@ -354,24 +354,24 @@ Please note that an empty or a space-only string is treated as `0` in all numeri
354
354
alert( Number.isFinite(123) ); // true
355
355
alert( Number.isFinite(Infinity) ); //false
356
356
alert( Number.isFinite(2 / 0) ); // false
357
-
357
+
358
358
// Note the difference:
359
359
alert( Number.isFinite("123") ); // false, because "123" belongs to the string type, not the number type
360
360
alert( isFinite("123") ); // true, because isFinite converts string "123" into a number 123
361
361
```
362
-
363
-
Do not consider `Number.isNaN` and `Number.isFinite` methods as the more "correct" versions of `isNaN` and `isFinite` functions. They complement each other and are equally essential for different tasks.
362
+
363
+
In a way, `Number.isNaN` and `Number.isFinite` are simpler and more straightforward than `isNaN` and `isFinite` functions. In practice though, `isNaN` and `isFinite` are mostly used, as they're shorter to write.
364
364
````
365
365
366
-
```smart header="Compare with `Object.is`"
366
+
```smart header="Comparison with `Object.is`"
367
367
There is a special built-in method `Object.is` that compares values like `===`, but is more reliable for two edge cases:
368
368
369
369
1. It works with `NaN`: `Object.is(NaN, NaN) === true`, that's a good thing.
370
370
2. Values `0` and `-0` are different: `Object.is(0, -0) === false`, technically that's true, because internally the number has a sign bit that may be different even if all other bits are zeroes.
371
371
372
372
In all other cases, `Object.is(a, b)` is the same as `a === b`.
373
373
374
-
This way of comparison is often used in JavaScript specification. When an internal algorithm needs to compare two values for being exactly the same, it uses `Object.is` (internally called [SameValue](https://tc39.github.io/ecma262/#sec-samevalue)).
374
+
We mention `Object.is` here, because it's often used in JavaScript specification. When an internal algorithm needs to compare two values for being exactly the same, it uses `Object.is` (internally called [SameValue](https://tc39.github.io/ecma262/#sec-samevalue)).
0 commit comments