minor fixes
This commit is contained in:
parent
689975093c
commit
f6ff773033
24 changed files with 67 additions and 76 deletions
|
@ -13,7 +13,7 @@ function checkAge(age) {
|
|||
if (age > 18) {
|
||||
return true;
|
||||
} else {
|
||||
return confirm('Do you have your parents permission to access this page?');
|
||||
return confirm('Did parents allow you?');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -14,10 +14,8 @@ let x = prompt("x?", '');
|
|||
let n = prompt("n?", '');
|
||||
|
||||
if (n < 1) {
|
||||
alert(`Power ${n} is not supported,
|
||||
use an integer greater than 0`);
|
||||
alert(`Степень ${n} не поддерживается, только целая, большая 0`);
|
||||
} else {
|
||||
alert( pow(x, n) );
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -20,9 +20,13 @@ function showMessage() {
|
|||
}
|
||||
```
|
||||
|
||||
The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (empty in the example above) and finally the code of the function, also named "the function body", between curly braces.
|
||||
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.
|
||||
|
||||

|
||||
```js
|
||||
function name(parameters) {
|
||||
...body...
|
||||
}
|
||||
```
|
||||
|
||||
Our new function can be called by its name: `showMessage()`.
|
||||
|
||||
|
@ -205,12 +209,11 @@ function showMessage(from, text = anotherFunction()) {
|
|||
```
|
||||
|
||||
```smart header="Evaluation of default parameters"
|
||||
In JavaScript, a default parameter is evaluated every time the function is called without the respective parameter. In the example above, `anotherFunction()` is called every time `showMessage()` is called without the `text` parameter.
|
||||
|
||||
In JavaScript, a default parameter is evaluated every time the function is called without the respective parameter. In the example above, `anotherFunction()` is called every time `showMessage()` is called without the `text` parameter. This is in contrast to some other languages like Python, where any default parameters are evaluated only once during the initial interpretation.
|
||||
|
||||
This is in contrast to some other languages like Python, where any default parameters are evaluated only once during the initial interpretation.
|
||||
```
|
||||
|
||||
|
||||
````smart header="Default parameters old-style"
|
||||
Old editions of JavaScript did not support default parameters. So there are alternative ways to support them, that you can find mostly in the old scripts.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue