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
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -205,7 +205,7 @@ Ouch! There are more consequences than an incorrect comparison here. Imagine you
205
205
206
206
But why does this happen?
207
207
208
-
A number is stored in memory in its binary form, a sequence of ones and zeroes. But fractions like `0.1`, `0.2` that look simple in the decimal numeric system are actually unending fractions in their binary form.
208
+
A number is stored in memory in its binary form, a sequence of bits - ones and zeroes. But fractions like `0.1`, `0.2` that look simple in the decimal numeric system are actually unending fractions in their binary form.
209
209
210
210
In other words, what is `0.1`? It is one divided by ten `1/10`, one-tenth. In decimal numeral system such numbers are easily representable. Compare it to one-third: `1/3`. It becomes an endless fraction `0.33333(3)`.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/06-iterable/article.md
+8-6Lines changed: 8 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -105,7 +105,7 @@ for (let num of range) {
105
105
106
106
Now `range[Symbol.iterator]()` returns the `range` object itself: it has the necessary `next()` method and remembers the current iteration progress in `this.current`. Shorter? Yes. And sometimes that's fine too.
107
107
108
-
The downside is that now it's impossible to have two `for..of` loops running over the object simultaneously: they'll share the iteration state, because there's only one iterator -- the object itself. But two parallel for-ofs is a rare thing, doable with some async scenarios.
108
+
The downside is that now it's impossible to have two `for..of` loops running over the object simultaneously: they'll share the iteration state, because there's only one iterator -- the object itself. But two parallel for-ofs is a rare thing, even in async scenarios.
109
109
110
110
```smart header="Infinite iterators"
111
111
Infinite iterators are also possible. For instance, the `range` becomes infinite for `range.to = Infinity`. Or we can make an iterable object that generates an infinite sequence of pseudorandom numbers. Also can be useful.
@@ -144,7 +144,7 @@ Normally, internals of iterables are hidden from the external code. There's a `f
144
144
145
145
But to understand things a little bit deeper let's see how to create an iterator explicitly.
146
146
147
-
We'll iterate over a string the same way as `for..of`, but with direct calls. This code gets a string iterator and calls it "manually":
147
+
We'll iterate over a string in exactlly the same way as `for..of`, but with direct calls. This code creates a string iterator and gets values from it "manually":
148
148
149
149
```js run
150
150
let str ="Hello";
@@ -170,7 +170,9 @@ There are two official terms that look similar, but are very different. Please m
170
170
-*Iterables* are objects that implement the `Symbol.iterator` method, as described above.
171
171
-*Array-likes* are objects that have indexes and `length`, so they look like arrays.
172
172
173
-
Naturally, these properties can combine. For instance, strings are both iterable (`for..of` works on them) and array-like (they have numeric indexes and `length`).
173
+
When we use JavaScript for practical tasks in browser or other environments, we may meet objects that are iterables or array-likes, or both.
174
+
175
+
For instance, strings are both iterable (`for..of` works on them) and array-like (they have numeric indexes and `length`).
174
176
175
177
But an iterable may be not array-like. And vice versa an array-like may be not iterable.
176
178
@@ -191,11 +193,11 @@ for (let item of arrayLike) {}
191
193
*/!*
192
194
```
193
195
194
-
What do they have in common? Both iterables and array-likes are usually *not arrays*, they don't have `push`, `pop` etc. That's rather inconvenient if we have such an object and want to work with it as with an array.
196
+
Both iterables and array-likes are usually *not arrays*, they don't have `push`, `pop` etc. That's rather inconvenient if we have such an object and want to work with it as with an array. E.g. we would like to work with `range` using array methods. How to achieve that?
195
197
196
198
## Array.from
197
199
198
-
There's a universal method [Array.from](mdn:js/Array/from) that brings them together. It takes an iterable or array-like value and makes a "real" `Array` from it. Then we can call array methods on it.
200
+
There's a universal method [Array.from](mdn:js/Array/from) that takes an iterable or array-like value and makes a "real" `Array` from it. Then we can call array methods on it.
199
201
200
202
For instance:
201
203
@@ -227,7 +229,7 @@ The full syntax for `Array.from` allows to provide an optional "mapping" functio
227
229
Array.from(obj[, mapFn, thisArg])
228
230
```
229
231
230
-
The second argument `mapFn`should be the function to apply to each element before adding to the array, and `thisArg` allows to set `this` for it.
232
+
The optional second argument `mapFn`can be a function that will be applied to each element before adding to the array, and `thisArg` allows to set `this` for it.
0 commit comments