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/01-getting-started/1-intro/article.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,9 +24,15 @@ Prohlížeč má zabudovaný engine, který se někdy nazývá „virtuální st
24
24
25
25
Různé enginy mají různá „kódová označení“. Například:
26
26
27
+
<<<<<<< HEAD
27
28
-[V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- v Chrome a Opeře.
28
29
-[SpiderMonkey](https://cs.wikipedia.org/wiki/SpiderMonkey) -- ve Firefoxu.
29
30
- Existují i jiná krycí jména, například „Chakra“ pro Internet Explorer, „ChakraCore“ pro Microsoft Edge, „Nitro“ a „SquirrelFish“ pro Safari, a tak dále.
31
+
=======
32
+
-[V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- in Chrome and Opera.
33
+
-[SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- in Firefox.
34
+
- ...There are other codenames like "Chakra" for IE, "JavaScriptCore", "Nitro" and "SquirrelFish" for Safari, etc.
35
+
>>>>>>> b09e38c5573346c401a9f9f7410b4ff9be5f4115
30
36
31
37
Výše uvedené pojmy je dobré si pamatovat, protože se používají ve vývojářských článcích na internetu. Budeme je používat i my. Například „vlastnost X je podporována ve V8“ znamená, že pravděpodobně bude fungovat v Chrome a Opeře.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/02-structure/article.md
+16-20Lines changed: 16 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ alert(3 +
46
46
+2);
47
47
```
48
48
49
-
The code outputs `6` because JavaScript does not insert semicolons here. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an "incomplete expression", so the semicolon is not required. And in this case that works as intended.
49
+
The code outputs `6` because JavaScript does not insert semicolons here. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an "incomplete expression", so a semicolon there would be incorrect. And in this case, that works as intended.
50
50
51
51
**But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.**
52
52
@@ -56,40 +56,36 @@ Errors which occur in such cases are quite hard to find and fix.
56
56
If you're curious to see a concrete example of such an error, check this code out:
57
57
58
58
```js run
59
-
[1, 2].forEach(alert)
59
+
alert("Hello");
60
+
61
+
[1, 2].forEach(alert);
60
62
```
61
63
62
-
No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of the code: it shows `1` then `2`.
64
+
No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of running the code: it shows `Hello`, then `1`, then `2`.
63
65
64
-
Now, let's add an `alert` before the code and *not* finish it with a semicolon:
66
+
Now let's remove the semicolon after the `alert`:
65
67
66
68
```js run no-beautify
67
-
alert("There will be an error")
69
+
alert("Hello")
68
70
69
-
[1, 2].forEach(alert)
71
+
[1, 2].forEach(alert);
70
72
```
71
73
72
-
Now if we run the code, only the first `alert` is shown and then we have an error!
73
-
74
-
But everything is fine again if we add a semicolon after `alert`:
75
-
```js run
76
-
alert("All fine now");
74
+
The difference compared to the code above is only one character: the semicolon at the end of the first line is gone.
77
75
78
-
[1, 2].forEach(alert)
79
-
```
76
+
If we run this code, only the first `Hello` shows (and there's an error, you may need to open the console to see it). There are no numbers any more.
80
77
81
-
Now we have the "All fine now" message followed by `1` and `2`.
78
+
That's because JavaScript does not assume a semicolon before square brackets `[...]`. So, the code in the last example is treated as a single statement.
82
79
83
-
84
-
The error in the no-semicolon variant occurs because JavaScript does not assume a semicolon before square brackets `[...]`.
85
-
86
-
So, because the semicolon is not auto-inserted, the code in the first example is treated as a single statement. Here's how the engine sees it:
80
+
Here's how the engine sees it:
87
81
88
82
```js run no-beautify
89
-
alert("There will be an error")[1, 2].forEach(alert)
83
+
alert("Hello")[1, 2].forEach(alert);
90
84
```
91
85
92
-
But it should be two separate statements, not one. Such a merging in this case is just wrong, hence the error. This can happen in other situations.
86
+
Looks weird, right? Such merging in this case is just wrong. We need to put a semicolon after `alert` for the code to work correctly.
87
+
88
+
This can happen in other situations also.
93
89
````
94
90
95
91
We recommend putting semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community. Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer -- especially for a beginner -- to use them.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/05-types/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ Special numeric values formally belong to the "number" type. Of course they are
64
64
65
65
We'll see more about working with numbers in the chapter <info:number>.
66
66
67
-
## BigInt
67
+
## BigInt[#bigint-type]
68
68
69
69
In JavaScript, the "number" type cannot represent integer values larger than <code>(2<sup>53</sup>-1)</code> (that's `9007199254740991`), or less than <code>-(2<sup>53</sup>-1)</code> for negatives. It's a technical limitation caused by their internal representation.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/15-function-basics/article.md
+32-19Lines changed: 32 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,10 +20,10 @@ function showMessage() {
20
20
}
21
21
```
22
22
23
-
The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (comma-separated, empty in the example above) and finally the code of the function, also named "the function body", between curly braces.
23
+
The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (comma-separated, empty in the example above, we'll see examples later) and finally the code of the function, also named "the function body", between curly braces.
When the function is called in lines `(*)` and `(**)`, the given values are copied to local variables `from` and `text`. Then the function uses them.
156
154
157
155
Here'sonemoreexample:wehaveavariable`from`andpassittothefunction. Please note: the function changes `from`, but the change is not seen outside, because a function always gets a copy of the value:
When a value is passed as a function parameter, it's also called an *argument*.
176
+
177
+
In other words, to put these terms straight:
178
+
179
+
- A parameter is the variable listed inside the parentheses in the function declaration (it's a declaration time term)
180
+
- An argument is the value that is passed to the function when it is called (it's a call time term).
181
+
182
+
We declare functions listing their parameters, then call them passing arguments.
183
+
184
+
In the example above, one might say: "the function `showMessage` is declared with two parameters, then called with two arguments: `from` and `"Hello"`".
185
+
186
+
178
187
## Default values
179
188
180
-
If a parameter is not provided, then its value becomes `undefined`.
189
+
If a function is called, but an argument is not provided, then the corresponding value becomes `undefined`.
181
190
182
191
For instance, the aforementioned function `showMessage(from, text)` can be called with a single argument:
183
192
184
193
```js
185
194
showMessage("Ann");
186
195
```
187
196
188
-
That's not an error. Such a call would output `"*Ann*: undefined"`. There's no `text`, so it's assumed that `text===undefined`.
197
+
That's not an error. Such a call would output `"*Ann*: undefined"`. As the value for `text` isn't passed, it becomes `undefined`.
189
198
190
-
If we want to use a "default" `text` in this case, then we can specify it after`=`:
199
+
We can specify the so-called "default" (to use if omitted) value for a parameter in the function declaration, using`=`:
191
200
192
201
```jsrun
193
202
functionshowMessage(from, *!*text="no text given"*/!*) {
@@ -211,19 +220,23 @@ function showMessage(from, text = anotherFunction()) {
211
220
```smartheader="Evaluation of default parameters"
212
221
InJavaScript, adefaultparameterisevaluatedeverytimethefunction is called without the respective parameter.
213
222
214
-
In the example above, `anotherFunction()` is called every time `showMessage()` is called without the `text` parameter.
223
+
In the example above, `anotherFunction()` isn't called at all, if the `text` parameter is provided.
224
+
225
+
On the other hand, it's independently called every time when `text` is missing.
215
226
```
216
227
217
228
### Alternative default parameters
218
229
219
-
Sometimes it makes sense to set default values for parameters not in the function declaration, but at a later stage, during its execution.
230
+
Sometimes it makes sense to assign default values for parameters not in the function declaration, but at a later stage.
220
231
221
-
To check for an omitted parameter, we can compare it with `undefined`:
232
+
We can check if the parameter is passed during the function execution, by comparing it with `undefined`:
222
233
223
234
```js run
224
235
function showMessage(text) {
236
+
// ...
237
+
225
238
*!*
226
-
if (text ===undefined) {
239
+
if (text ===undefined) {// if the parameter is missing
// if text parameter is omitted or "" is passed, set it to 'empty'
241
253
functionshowMessage(text) {
254
+
// if text is undefined or otherwise falsy, set it to 'empty'
242
255
text = text ||'empty';
243
256
...
244
257
}
245
258
```
246
259
247
-
Modern JavaScript engines support the [nullish coalescing operator](info:nullish-coalescing-operator) `??`, it's better when falsy values, such as `0`, are considered regular:
260
+
Modern JavaScript engines support the [nullish coalescing operator](info:nullish-coalescing-operator) `??`, it's better when most falsy values, such as `0`, should be considered "normal":
248
261
249
262
```js run
250
-
// if there's no "count" parameter, show "unknown"
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/06-polyfills/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ Here, in this chapter, our purpose is to get the gist of how they work, and thei
22
22
23
23
## Transpilers
24
24
25
-
A [transpiler](https://en.wikipedia.org/wiki/Source-to-source_compiler) is a special piece of software that can parse ("read and understand") modern code, and rewrite it using older syntax constructs, so that the result would be the same.
25
+
A [transpiler](https://en.wikipedia.org/wiki/Source-to-source_compiler) is a special piece of software that translates source code to another source code. It can parse ("read and understand") modern code and rewrite it using older syntax constructs, so that it'll also work in outdated engines.
26
26
27
27
E.g. JavaScript before year 2020 didn't have the "nullish coalescing operator" `??`. So, if a visitor uses an outdated browser, it may fail to understand the code like `height = height ?? 100`.
0 commit comments