Skip to content

Commit b140203

Browse files
committed
Merging with upstream @be342e50
2 parents 52eead9 + be342e5 commit b140203

168 files changed

Lines changed: 4332 additions & 735 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1-js/01-getting-started/3-code-editors/article.md

Lines changed: 0 additions & 63 deletions
This file was deleted.

1-js/01-getting-started/4-devtools/article.md

Lines changed: 0 additions & 62 deletions
This file was deleted.

1-js/02-first-steps/08-comparison/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Why does it dislike zero so much? Always false!
193193
We get these results because:
194194

195195
- Comparisons `(1)` and `(2)` return `false` because `undefined` gets converted to `NaN` and `NaN` is a special numeric value which returns `false` for all comparisons.
196-
- The equality check `(3)` returns `false` because `undefined` only equals `null` and no other value.
196+
- The equality check `(3)` returns `false` because `undefined` only equals `null`, `undefined`, and no other value.
197197

198198
### Evade problems
199199

1-js/02-first-steps/09-alert-prompt-confirm/article.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ The function `prompt` accepts two arguments:
3030
result = prompt(title[, default]);
3131
```
3232

33-
It shows a modal window with a text message, an input field for the visitor, and the buttons OK/CANCEL.
33+
It shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel.
3434

3535
`title`
3636
: The text to show the visitor.
3737

3838
`default`
3939
: An optional second parameter, the initial value for the input field.
4040

41-
The visitor may type something in the prompt input field and press OK. Or they can cancel the input by pressing CANCEL or hitting the `key:Esc` key.
41+
The visitor may type something in the prompt input field and press OK. Or they can cancel the input by pressing Cancel or hitting the `key:Esc` key.
4242

4343
The call to `prompt` returns the text from the input field or `null` if the input was canceled.
4444

@@ -74,7 +74,7 @@ The syntax:
7474
result = confirm(question);
7575
```
7676
77-
The function `confirm` shows a modal window with a `question` and two buttons: OK and CANCEL.
77+
The function `confirm` shows a modal window with a `question` and two buttons: OK and Cancel.
7878
7979
The result is `true` if OK is pressed and `false` otherwise.
8080
@@ -94,10 +94,10 @@ We covered 3 browser-specific functions to interact with visitors:
9494
: shows a message.
9595
9696
`prompt`
97-
: shows a message asking the user to input text. It returns the text or, if CANCEL or `key:Esc` is clicked, `null`.
97+
: shows a message asking the user to input text. It returns the text or, if Cancel button or `key:Esc` is clicked, `null`.
9898
9999
`confirm`
100-
: shows a message and waits for the user to press "OK" or "CANCEL". It returns `true` for OK and `false` for CANCEL/`key:Esc`.
100+
: shows a message and waits for the user to press "OK" or "Cancel". It returns `true` for OK and `false` for Cancel/`key:Esc`.
101101
102102
All these methods are modal: they pause script execution and don't allow the visitor to interact with the rest of the page until the window has been dismissed.
103103

1-js/02-first-steps/12-while-for/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ while (i) { // when i becomes 0, the condition becomes falsy, and the loop stops
4747
}
4848
```
4949

50-
````smart header="Brackets are not required for a single-line body"
51-
If the loop body has a single statement, we can omit the brackets `{…}`:
50+
````smart header="Curly braces are not required for a single-line body"
51+
If the loop body has a single statement, we can omit the curly braces `{…}`:
5252
5353
```js run
5454
let i = 3;

1-js/02-first-steps/15-function-expressions-arrows/article.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ We can pass it between variables and run when we want.
175175

176176
Let's formulate the key differences between Function Declarations and Expressions.
177177

178-
First, the syntax: how to see what is what in the code.
178+
First, the syntax: how to differentiate between them in the code.
179179

180180
- *Function Declaration:* a function, declared as a separate statement, in the main code flow.
181181

@@ -186,7 +186,7 @@ First, the syntax: how to see what is what in the code.
186186
}
187187
```
188188
- *Function Expression:* a function, created inside an expression or inside another syntax construct. Here, the function is created at the right side of the "assignment expression" `=`:
189-
189+
190190
```js
191191
// Function Expression
192192
let sum = function(a, b) {
@@ -196,19 +196,20 @@ First, the syntax: how to see what is what in the code.
196196

197197
The more subtle difference is *when* a function is created by the JavaScript engine.
198198

199-
**A Function Expression is created when the execution reaches it and is usable from then on.**
199+
**A Function Expression is created when the execution reaches it and is usable only from that moment.**
200200

201201
Once the execution flow passes to the right side of the assignment `let sum = function…` -- here we go, the function is created and can be used (assigned, called, etc. ) from now on.
202202

203203
Function Declarations are different.
204204

205-
**A Function Declaration is usable in the whole script/code block.**
205+
**A Function Declaration can be called earlier than it is defined.**
206+
207+
For example, a global Function Declaration is visible in the whole script, no matter where it is.
206208

207-
In other words, when JavaScript *prepares* to run the script or a code block, it first looks for Function Declarations in it and creates the functions. We can think of it as an "initialization stage".
209+
That's due to internal algorithms. When JavaScript prepares to run the script, it first looks for global Function Declarations in it and creates the functions. We can think of it as an "initialization stage".
208210

209-
And after all of the Function Declarations are processed, the execution goes on.
211+
And after all Function Declarations are processed, the code is executed. So it has access to these functions.
210212

211-
As a result, a function declared as a Function Declaration can be called earlier than it is defined.
212213

213214
For example, this works:
214215

@@ -224,7 +225,7 @@ function sayHi(name) {
224225

225226
The Function Declaration `sayHi` is created when JavaScript is preparing to start the script and is visible everywhere in it.
226227

227-
...If it was a Function Expression, then it wouldn't work:
228+
...If it were a Function Expression, then it wouldn't work:
228229

229230
```js run refresh untrusted
230231
*!*
@@ -238,13 +239,11 @@ let sayHi = function(name) { // (*) no magic any more
238239

239240
Function Expressions are created when the execution reaches them. That would happen only in the line `(*)`. Too late.
240241

241-
**When a Function Declaration is made within a code block, it is visible everywhere inside that block. But not outside of it.**
242-
243-
Sometimes that's handy to declare a local function only needed in that block alone. But that feature may also cause problems.
242+
**In strict mode, when a Function Declaration is within a code block, it's visible everywhere inside that block. But not outside of it.**
244243

245244
For instance, let's imagine that we need to declare a function `welcome()` depending on the `age` variable that we get during runtime. And then we plan to use it some time later.
246245

247-
The code below doesn't work:
246+
If we use Function Declaration, it won't work as intended:
248247

249248
```js run
250249
let age = prompt("What is your age?", 18);
@@ -350,12 +349,12 @@ welcome(); // ok now
350349
```
351350

352351

353-
```smart header="When should you choose Function Declaration versus Function Expression?"
354-
As a rule of thumb, when we need to declare a function, the first to consider is Function Declaration syntax, the one we used before. It gives more freedom in how to organize our code, because we can call such functions before they are declared.
352+
```smart header="When to choose Function Declaration versus Function Expression?"
353+
As a rule of thumb, when we need to declare a function, the first to consider is Function Declaration syntax. It gives more freedom in how to organize our code, because we can call such functions before they are declared.
355354
356-
It's also a little bit easier to look up `function f(…) {…}` in the code than `let f = function(…) {…}`. Function Declarations are more "eye-catching".
355+
That's also better for readability, as it's easier to look up `function f(…) {…}` in the code than `let f = function(…) {…}`. Function Declarations are more "eye-catching".
357356
358-
...But if a Function Declaration does not suit us for some reason (we've seen an example above), then Function Expression should be used.
357+
...But if a Function Declaration does not suit us for some reason, or we need a conditional declaration (we've just seen an example), then Function Expression should be used.
359358
```
360359

361360

0 commit comments

Comments
 (0)