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
+14-6Lines changed: 14 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -16,21 +16,29 @@ Imagine we need to write 1 billion. The obvious way is:
16
16
let billion =1000000000;
17
17
```
18
18
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:
20
20
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:
22
30
23
31
```js run
24
32
let billion =1e9; // 1 billion, literally: 1 and 9 zeroes
25
33
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)
27
35
```
28
36
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.
30
38
31
39
```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
34
42
```
35
43
36
44
Now let's write something very small. Say, 1 microsecond (one millionth of a second):
0 commit comments