commit
c3b5dc1748
2 changed files with 5 additions and 5 deletions
|
@ -4,7 +4,7 @@ In modern JavaScript, there are two types of numbers:
|
||||||
|
|
||||||
1. Regular numbers in JavaScript are stored in 64-bit format [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754-2008_revision), also known as "double precision floating point numbers". These are numbers that we're using most of the time, and we'll talk about them in this chapter.
|
1. Regular numbers in JavaScript are stored in 64-bit format [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754-2008_revision), also known as "double precision floating point numbers". These are numbers that we're using most of the time, and we'll talk about them in this chapter.
|
||||||
|
|
||||||
2. BigInt numbers, to represent integers of arbitrary length. They are sometimes needed, because a regular number can't safely exceed <code>2<sup>53</sup></code> or be less than <code>-2<sup>53</sup></code>. As bigints are used in few special areas, we devote them a special chapter <info:bigint>.
|
2. BigInt numbers represent integers of arbitrary length. They are sometimes needed because a regular number can't safely exceed <code>2<sup>53</sup></code> or be less than <code>-2<sup>53</sup></code>. As bigints are used in few special areas, we devote them a special chapter <info:bigint>.
|
||||||
|
|
||||||
So here we'll talk about regular numbers. Let's expand our knowledge of them.
|
So here we'll talk about regular numbers. Let's expand our knowledge of them.
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ They belong to the type `number`, but are not "normal" numbers, so there are spe
|
||||||
alert( isNaN("str") ); // true
|
alert( isNaN("str") ); // true
|
||||||
```
|
```
|
||||||
|
|
||||||
But do we need this function? Can't we just use the comparison `=== NaN`? Sorry, but the answer is no. The value `NaN` is unique in that it does not equal anything, including itself:
|
But do we need this function? Can't we just use the comparison `=== NaN`? Unfortunately not. The value `NaN` is unique in that it does not equal anything, including itself:
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
alert( NaN === NaN ); // false
|
alert( NaN === NaN ); // false
|
||||||
|
@ -402,7 +402,7 @@ A few examples:
|
||||||
alert( Math.random() ); // ... (any random numbers)
|
alert( Math.random() ); // ... (any random numbers)
|
||||||
```
|
```
|
||||||
|
|
||||||
`Math.max(a, b, c...)` / `Math.min(a, b, c...)`
|
`Math.max(a, b, c...)` and `Math.min(a, b, c...)`
|
||||||
: Returns the greatest/smallest from the arbitrary number of arguments.
|
: Returns the greatest/smallest from the arbitrary number of arguments.
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
|
|
|
@ -96,7 +96,7 @@ The "trailing comma" style makes it easier to insert/remove items, because all l
|
||||||
|
|
||||||
[recent browser="new"]
|
[recent browser="new"]
|
||||||
|
|
||||||
Let's say we want a last element of the array.
|
Let's say we want the last element of the array.
|
||||||
|
|
||||||
Some programming languages allow to use negative indexes for the same purpose, like `fruits[-1]`.
|
Some programming languages allow to use negative indexes for the same purpose, like `fruits[-1]`.
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ It's rarely used, because square brackets `[]` are shorter. Also, there's a tric
|
||||||
|
|
||||||
If `new Array` is called with a single argument which is a number, then it creates an array *without items, but with the given length*.
|
If `new Array` is called with a single argument which is a number, then it creates an array *without items, but with the given length*.
|
||||||
|
|
||||||
Let's see how one can shoot themself in the foot:
|
Let's see how one can shoot themselves in the foot:
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
let arr = new Array(2); // will it create an array of [2] ?
|
let arr = new Array(2); // will it create an array of [2] ?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue