Skip to content

Commit ee2a942

Browse files
authored
Merge pull request #128 from javascript-tutorial/sync-18b1314a
Sync with upstream @ 18b1314
2 parents d1714a3 + 9b4955e commit ee2a942

File tree

25 files changed

+322
-311
lines changed

25 files changed

+322
-311
lines changed

1-js/02-first-steps/04-variables/3-uppercast-constant/task.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,24 @@ const datumNarození = '18.04.1982';
1212
const věk = nějakýKód(datumNarození);
1313
```
1414

15+
<<<<<<< HEAD
1516
Zde máme konstantu `datumNarození` a pomocí nějakého kódu se z této proměnné vypočítá `věk` (kód není pro stručnost uveden, na podrobnostech zde nezáleží).
17+
=======
18+
Here we have a constant `birthday` for the date, and also the `age` constant.
19+
20+
The `age` is calculated from `birthday` using `someCode()`, which means a function call that we didn't explain yet (we will soon!), but the details don't matter here, the point is that `age` is calculated somehow based on the `birthday`.
21+
>>>>>>> 18b1314af4e0ead5a2b10bb4bacd24cecbb3f18e
1622
1723
Bylo by správné použít pro název proměnné `datumNarození` velká písmena? A pro `věk`? Nebo dokonce pro obě?
1824

1925
```js
26+
<<<<<<< HEAD
2027
const DATUM_NAROZENÍ = '18.04.1982'; // velkými písmeny?
2128

2229
const VĚK = nějakýKód(DATUM_NAROZENÍ); // velkými písmeny?
23-
```
30+
=======
31+
const BIRTHDAY = '18.04.1982'; // make birthday uppercase?
2432

33+
const AGE = someCode(BIRTHDAY); // make age uppercase?
34+
>>>>>>> 18b1314af4e0ead5a2b10bb4bacd24cecbb3f18e
35+
```

1-js/02-first-steps/08-operators/3-primitive-conversions-questions/solution.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@ undefined + 1 = NaN // (6)
1616
" \t \n" - 2 = -2 // (7)
1717
```
1818

19+
<<<<<<< HEAD
1920
1. Sčítání s řetězcem `"" + 1` převede `1` na řetězec: `"" + 1 = "1"`, pak tedy budeme mít `"1" + 0` a použije se stejné pravidlo.
2021
2. Odčítání `-` (stejně jako většina matematických operací) pracuje jen s čísly, takže převede prázdný řetězec `""` na `0`.
2122
3. Sčítání s řetězcem připojí k řetězci číslo `5`.
2223
4. Odčítání vždy převádí operandy na čísla, takže vyrobí z `" -9 "` číslo `-9` (mezery okolo něj se ignorují).
2324
5. `null` se převede na číslo `0`.
2425
6. `undefined` se převede na číslo `NaN`.
2526
7. Když se řetězec převádí na číslo, mezerové znaky se z jeho začátku a konce odříznou. V tomto případě se celý řetězec skládá z mezerových znaků, konkrétně `\t`, `\n` a „obyčejné“ mezery mezi nimi. Stejně jako prázdný řetězec se tedy převede na `0`.
27+
=======
28+
1. The addition with a string `"" + 1` converts `1` to a string: `"" + 1 = "1"`, and then we have `"1" + 0`, the same rule is applied.
29+
2. The subtraction `-` (like most math operations) only works with numbers, it converts an empty string `""` to `0`.
30+
3. The addition with a string appends the number `5` to the string.
31+
4. The subtraction always converts to numbers, so it makes `" -9 "` a number `-9` (ignoring spaces around it).
32+
5. `null` becomes `0` after the numeric conversion.
33+
6. `undefined` becomes `NaN` after the numeric conversion.
34+
7. Space characters are trimmed off string start and end when a string is converted to a number. Here the whole string consists of space characters, such as `\t`, `\n` and a "regular" space between them. So, similarly to an empty string, it becomes `0`.
35+
>>>>>>> 18b1314af4e0ead5a2b10bb4bacd24cecbb3f18e

1-js/04-object-basics/02-object-copy/article.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,17 @@ We can also use the method [Object.assign](https://developer.mozilla.org/en-US/d
160160
The syntax is:
161161

162162
```js
163-
Object.assign(dest, src1[, src2, src3...])
163+
Object.assign(dest, ...sources)
164164
```
165165

166166
- The first argument `dest` is a target object.
167-
- Further arguments `src1, ..., srcN` (can be as many as needed) are source objects.
168-
- It copies the properties of all source objects `src1, ..., srcN` into the target `dest`. In other words, properties of all arguments starting from the second are copied into the first object.
169-
- The call returns `dest`.
167+
- Further arguments is a list of source objects.
170168

171-
For instance, we can use it to merge several objects into one:
172-
```js
169+
It copies the properties of all source objects into the target `dest`, and then returns it as the result.
170+
171+
For example, we have `user` object, let's add a couple of permissions to it:
172+
173+
```js run
173174
let user = { name: "John" };
174175
175176
let permissions1 = { canView: true };
@@ -181,6 +182,9 @@ Object.assign(user, permissions1, permissions2);
181182
*/!*
182183
183184
// now user = { name: "John", canView: true, canEdit: true }
185+
alert(user.name); // John
186+
alert(user.canView); // true
187+
alert(user.canEdit); // true
184188
```
185189
186190
If the copied property name already exists, it gets overwritten:
@@ -193,9 +197,9 @@ Object.assign(user, { name: "Pete" });
193197
alert(user.name); // now user = { name: "Pete" }
194198
```
195199
196-
We also can use `Object.assign` to replace `for..in` loop for simple cloning:
200+
We also can use `Object.assign` to perform a simple object cloning:
197201
198-
```js
202+
```js run
199203
let user = {
200204
name: "John",
201205
age: 30
@@ -204,9 +208,12 @@ let user = {
204208
*!*
205209
let clone = Object.assign({}, user);
206210
*/!*
211+
212+
alert(clone.name); // John
213+
alert(clone.age); // 30
207214
```
208215
209-
It copies all properties of `user` into the empty object and returns it.
216+
Here it copies all properties of `user` into the empty object and returns it.
210217
211218
There are also other methods of cloning an object, e.g. using the [spread syntax](info:rest-parameters-spread) `clone = {...user}`, covered later in the tutorial.
212219

1-js/04-object-basics/06-constructor-new/1-two-functions-one-object/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Is it possible to create functions `A` and `B` so that `new A() == new B()`?
1010
function A() { ... }
1111
function B() { ... }
1212

13-
let a = new A;
14-
let b = new B;
13+
let a = new A();
14+
let b = new B();
1515

1616
alert( a == b ); // true
1717
```

1-js/04-object-basics/06-constructor-new/2-calculator-constructor/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ importance: 5
66

77
Create a constructor function `Calculator` that creates objects with 3 methods:
88

9-
- `read()` asks for two values using `prompt` and remembers them in object properties.
9+
- `read()` prompts for two values and saves them as object properties with names `a` and `b` respectively.
1010
- `sum()` returns the sum of these properties.
1111
- `mul()` returns the multiplication product of these properties.
1212

1-js/04-object-basics/06-constructor-new/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ alert( new SmallUser().name ); // John
171171
Usually constructors don't have a `return` statement. Here we mention the special behavior with returning objects mainly for the sake of completeness.
172172

173173
````smart header="Omitting parentheses"
174-
By the way, we can omit parentheses after `new`, if it has no arguments:
174+
By the way, we can omit parentheses after `new`:
175175
176176
```js
177177
let user = new User; // <-- no parentheses

1-js/05-data-types/02-number/2-why-rounded-down/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ Note that `63.5` has no precision loss at all. That's because the decimal part `
2828

2929

3030
```js run
31-
alert( Math.round(6.35 * 10) / 10); // 6.35 -> 63.5 -> 64(rounded) -> 6.4
31+
alert( Math.round(6.35 * 10) / 10 ); // 6.35 -> 63.5 -> 64(rounded) -> 6.4
3232
```
3333

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ Please note that an empty or a space-only string is treated as `0` in all numeri
352352

353353
```js run
354354
alert( Number.isFinite(123) ); // true
355-
alert( Number.isFinite(Infinity) ); //false
355+
alert( Number.isFinite(Infinity) ); // false
356356
alert( Number.isFinite(2 / 0) ); // false
357357

358358
// Note the difference:
@@ -367,7 +367,7 @@ In a way, `Number.isNaN` and `Number.isFinite` are simpler and more straightforw
367367
There is a special built-in method `Object.is` that compares values like `===`, but is more reliable for two edge cases:
368368

369369
1. It works with `NaN`: `Object.is(NaN, NaN) === true`, that's a good thing.
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.
370+
2. Values `0` and `-0` are different: `Object.is(0, -0) === false`, technically that's correct, because internally the number has a sign bit that may be different even if all other bits are zeroes.
371371

372372
In all other cases, `Object.is(a, b)` is the same as `a === b`.
373373

1-js/05-data-types/03-string/1-ucfirst/solution.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ let newStr = str[0].toUpperCase() + str.slice(1);
88

99
There's a small problem though. If `str` is empty, then `str[0]` is `undefined`, and as `undefined` doesn't have the `toUpperCase()` method, we'll get an error.
1010

11-
There are two variants here:
12-
13-
1. Use `str.charAt(0)`, as it always returns a string (maybe empty).
14-
2. Add a test for an empty string.
15-
16-
Here's the 2nd variant:
11+
The easiest way out is to add a test for an empty string, like this:
1712

1813
```js run demo
1914
function ucFirst(str) {
@@ -24,4 +19,3 @@ function ucFirst(str) {
2419

2520
alert( ucFirst("john") ); // John
2621
```
27-

0 commit comments

Comments
 (0)