Skip to content

Commit 15e6f2d

Browse files
committed
minor fixes
1 parent 4307531 commit 15e6f2d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

1-js/05-data-types/02-number/article.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,29 @@ Imagine we need to write 1 billion. The obvious way is:
1616
let billion = 1000000000;
1717
```
1818

19-
But in real life, we usually avoid writing a long string of zeroes as it's easy to mistype. Also, we are lazy. We will usually write something like `"1bn"` for a billion or `"7.3bn"` for 7 billion 300 million. The same is true for most large numbers.
19+
We also can use underscope `_` as the separator:
2020

21-
In JavaScript, we shorten a number by appending the letter `"e"` to the number and specifying the zeroes count:
21+
```js
22+
let billion = 1_000_000_000;
23+
```
24+
25+
Here the underscore `_` plays the role of the "syntactic sugar", it makes the number more readable. The JavaScript engine simply ignores `_` between digits, so it's exactly the same one billion as above.
26+
27+
In real life though, we try to avoid writing long sequences of zeroes. We're too lazy for that. We'll try to write something like `"1bn"` for a billion or `"7.3bn"` for 7 billion 300 million. The same is true for most large numbers.
28+
29+
In JavaScript, we can shorten a number by appending the letter `"e"` to it and specifying the zeroes count:
2230

2331
```js run
2432
let billion = 1e9; // 1 billion, literally: 1 and 9 zeroes
2533

26-
alert( 7.3e9 ); // 7.3 billions (7,300,000,000)
34+
alert( 7.3e9 ); // 7.3 billions (same as 7300000000 or 7_300_000_000)
2735
```
2836

29-
In other words, `"e"` multiplies the number by `1` with the given zeroes count.
37+
In other words, `e` multiplies the number by `1` with the given zeroes count.
3038

3139
```js
32-
1e3 = 1 * 1000
33-
1.23e6 = 1.23 * 1000000
40+
1e3 = 1 * 1000 // e3 means *1000
41+
1.23e6 = 1.23 * 1000000 // e6 means *1000000
3442
```
3543

3644
Now let's write something very small. Say, 1 microsecond (one millionth of a second):

0 commit comments

Comments
 (0)