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
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
16
22
17
23
Bylo by správné použít pro název proměnné `datumNarození` velká písmena? A pro `věk`? Nebo dokonce pro obě?
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/08-operators/3-primitive-conversions-questions/solution.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,10 +16,20 @@ undefined + 1 = NaN // (6)
16
16
"\t\n"-2=-2// (7)
17
17
```
18
18
19
+
<<<<<<< HEAD
19
20
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.
20
21
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`.
21
22
3. Sčítání s řetězcem připojí k řetězci číslo `5`.
22
23
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í).
23
24
5.`null` se převede na číslo `0`.
24
25
6.`undefined` se převede na číslo `NaN`.
25
26
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`.
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/02-object-copy/article.md
+16-9Lines changed: 16 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -160,16 +160,17 @@ We can also use the method [Object.assign](https://developer.mozilla.org/en-US/d
160
160
The syntax is:
161
161
162
162
```js
163
-
Object.assign(dest, src1[, src2, src3...])
163
+
Object.assign(dest, ...sources)
164
164
```
165
165
166
166
- 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.
170
168
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:
We also can use `Object.assign` to replace `for..in` loop forsimple cloning:
200
+
We also can use `Object.assign` to perform a simple object cloning:
197
201
198
-
```js
202
+
```js run
199
203
let user = {
200
204
name: "John",
201
205
age: 30
@@ -204,9 +208,12 @@ let user = {
204
208
*!*
205
209
let clone = Object.assign({}, user);
206
210
*/!*
211
+
212
+
alert(clone.name); // John
213
+
alert(clone.age); // 30
207
214
```
208
215
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.
210
217
211
218
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.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/02-number/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -352,7 +352,7 @@ Please note that an empty or a space-only string is treated as `0` in all numeri
352
352
353
353
```js run
354
354
alert( Number.isFinite(123) ); // true
355
-
alert( Number.isFinite(Infinity) ); //false
355
+
alert( Number.isFinite(Infinity) ); //false
356
356
alert( Number.isFinite(2 / 0) ); // false
357
357
358
358
// Note the difference:
@@ -367,7 +367,7 @@ In a way, `Number.isNaN` and `Number.isFinite` are simpler and more straightforw
367
367
There is a special built-in method `Object.is` that compares values like `===`, but is more reliable for two edge cases:
368
368
369
369
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.
371
371
372
372
In all other cases, `Object.is(a, b)` is the same as `a === b`.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/03-string/1-ucfirst/solution.md
+1-7Lines changed: 1 addition & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,12 +8,7 @@ let newStr = str[0].toUpperCase() + str.slice(1);
8
8
9
9
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.
10
10
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:
0 commit comments