minor typos and English improvements
This commit is contained in:
parent
291b5c05b9
commit
d62faffa0d
1 changed files with 4 additions and 4 deletions
|
@ -90,7 +90,7 @@ Everything would work the same.
|
|||
|
||||
|
||||
````smart header="Why is there a semicolon at the end?"
|
||||
You might wonder, why does Function Expression have a semicolon `;` at the end, but Function Declaration does not:
|
||||
You might wonder, why do Function Expressions have a semicolon `;` at the end, but Function Declarations do not:
|
||||
|
||||
```js
|
||||
function sayHi() {
|
||||
|
@ -144,13 +144,13 @@ function showCancel() {
|
|||
ask("Do you agree?", showOk, showCancel);
|
||||
```
|
||||
|
||||
In practice, such functions are quite useful. The major difference between a real-life `ask` and the example above is that real-life functions use more complex ways to interact with the user than a simple `confirm`. In the browser, such function usually draws a nice-looking question window. But that's another story.
|
||||
In practice, such functions are quite useful. The major difference between a real-life `ask` and the example above is that real-life functions use more complex ways to interact with the user than a simple `confirm`. In the browser, such functions usually draw a nice-looking question window. But that's another story.
|
||||
|
||||
**The arguments `showOk` and `showCancel` of `ask` are called *callback functions* or just *callbacks*.**
|
||||
|
||||
The idea is that we pass a function and expect it to be "called back" later if necessary. In our case, `showOk` becomes the callback for "yes" answer, and `showCancel` for "no" answer.
|
||||
|
||||
We can use Function Expressions to write the same function much shorter:
|
||||
We can use Function Expressions to write an equivalent, shorter function:
|
||||
|
||||
```js run no-beautify
|
||||
function ask(question, yes, no) {
|
||||
|
@ -186,7 +186,7 @@ Let's formulate the key differences between Function Declarations and Expression
|
|||
|
||||
First, the syntax: how to differentiate between them in the code.
|
||||
|
||||
- *Function Declaration:* a function, declared as a separate statement, in the main code flow.
|
||||
- *Function Declaration:* a function, declared as a separate statement, in the main code flow:
|
||||
|
||||
```js
|
||||
// Function Declaration
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue