Skip to content

Commit e6fb8a9

Browse files
committed
translate examples
1 parent aeab77d commit e6fb8a9

1 file changed

Lines changed: 67 additions & 23 deletions

File tree

1-js/02-first-steps/14-function-basics/article.md

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ It looks like this:
1616

1717
```js
1818
function showMessage() {
19-
alert( 'Hello everyone!' );
19+
alert( 'Всем привет!' );
2020
}
2121
```
2222

@@ -30,7 +30,7 @@ For instance:
3030

3131
```js run
3232
function showMessage() {
33-
alert( 'Hello everyone!' );
33+
alert( 'Всем привет!' );
3434
}
3535

3636
*!*
@@ -54,13 +54,17 @@ For example:
5454
```js run
5555
function showMessage() {
5656
*!*
57+
<<<<<<< HEAD
5758
let message = "Hello, I'm JavaScript!"; // local variable
59+
=======
60+
let message = "Привет, я JavaScript!"; // локальная переменная
61+
>>>>>>> translate examples
5862
*/!*
5963

6064
alert( message );
6165
}
6266

63-
showMessage(); // Hello, I'm JavaScript!
67+
showMessage(); // Привет, я JavaScript!
6468

6569
alert( message ); // <-- Error! The variable is local to the function
6670
```
@@ -70,57 +74,77 @@ alert( message ); // <-- Error! The variable is local to the function
7074
A function can access an outer variable as well, for example:
7175

7276
```js run no-beautify
73-
let *!*userName*/!* = 'John';
77+
let *!*userName*/!* = 'Вася';
7478

7579
function showMessage() {
76-
let message = 'Hello, ' + *!*userName*/!*;
80+
let message = 'Привет, ' + *!*userName*/!*;
7781
alert(message);
7882
}
7983

80-
showMessage(); // Hello, John
84+
showMessage(); // Привет, Вася
8185
```
8286

8387
The function has full access to the outer variable. It can modify it as well.
8488

8589
For instance:
8690

8791
```js run
88-
let *!*userName*/!* = 'John';
92+
let *!*userName*/!* = 'Вася';
8993

9094
function showMessage() {
95+
<<<<<<< HEAD
9196
*!*userName*/!* = "Bob"; // (1) changed the outer variable
97+
=======
98+
*!*userName*/!* = "Петя"; // (1) изменяем значение внешней переменной
99+
>>>>>>> translate examples
92100

93-
let message = 'Hello, ' + *!*userName*/!*;
101+
let message = 'Привет, ' + *!*userName*/!*;
94102
alert(message);
95103
}
96104

105+
<<<<<<< HEAD
97106
alert( userName ); // *!*John*/!* before the function call
98107

99108
showMessage();
100109

101110
alert( userName ); // *!*Bob*/!*, the value was modified by the function
111+
=======
112+
alert( userName ); // *!*Вася*/!* перед вызовом функции
113+
114+
showMessage();
115+
116+
alert( userName ); // *!*Петя*/!*, значение внешней переменной было изменено функцией
117+
>>>>>>> translate examples
102118
```
103119

104120
The outer variable is only used if there's no local one. So an occasional modification may happen if we forget `let`.
105121

106122
If a same-named variable is declared inside the function then it *shadows* the outer one. For instance, in the code below the function uses the local `userName`. The outer one is ignored:
107123

108124
```js run
109-
let userName = 'John';
125+
let userName = 'Вася';
110126

111127
function showMessage() {
112128
*!*
129+
<<<<<<< HEAD
113130
let userName = "Bob"; // declare a local variable
131+
=======
132+
let userName = "Петя"; // объявляем локальную переменную
133+
>>>>>>> translate examples
114134
*/!*
115135

116-
let message = 'Hello, ' + userName; // *!*Bob*/!*
136+
let message = 'Привет, ' + userName; // *!*Петя*/!*
117137
alert(message);
118138
}
119139

120140
// the function will create and use its own userName
121141
showMessage();
122142

143+
<<<<<<< HEAD
123144
alert( userName ); // *!*John*/!*, unchanged, the function did not access the outer variable
145+
=======
146+
alert( userName ); // *!*Вася*/!*, не изменилась, у функции нет доступа в внешней переменной
147+
>>>>>>> translate examples
124148
```
125149

126150
```smart header="Global variables"
@@ -143,8 +167,8 @@ function showMessage(*!*from, text*/!*) { // arguments: from, text
143167
}
144168

145169
*!*
146-
showMessage('Ann', 'Hello!'); // Ann: Hello! (*)
147-
showMessage('Ann', "What's up?"); // Ann: What's up? (**)
170+
showMessage('Аня', 'Привет!'); // Аня: Привет! (*)
171+
showMessage('Аня', "Как дела?"); // Аня: Как дела? (**)
148172
*/!*
149173
```
150174
@@ -163,12 +187,17 @@ function showMessage(from, text) {
163187
alert( from + ': ' + text );
164188
}
165189

166-
let from = "Ann";
190+
let from = "Аня";
167191

168-
showMessage(from, "Hello"); // *Ann*: Hello
192+
showMessage(from, "Привет"); // *Аня*: Привет
169193

194+
<<<<<<< HEAD
170195
// the value of "from" is the same, the function modified a local copy
171196
alert( from ); // Ann
197+
=======
198+
// значение "from" осталось прежним, функция изменила значение локальной переменной
199+
alert( from ); // Аня
200+
>>>>>>> translate examples
172201
```
173202
174203
## Default values
@@ -178,24 +207,34 @@ If a parameter is not provided, then its value becomes `undefined`.
178207
For instance, the aforementioned function `showMessage(from, text)` can be called with a single argument:
179208
180209
```js
181-
showMessage("Ann");
210+
showMessage("Аня");
182211
```
183212
213+
<<<<<<< HEAD
184214
That's not an error. Such a call would output `"Ann: undefined"`. There's no `text`, so it's assumed that `text === undefined`.
215+
=======
216+
Это не приведёт к ошибке. Такой вызов выведет `"Аня: undefined"`. В вызове не указан параметр `text`, поэтому предполагается, что `text === undefined`.
217+
>>>>>>> translate examples
185218
186219
If we want to use a "default" `text` in this case, then we can specify it after `=`:
187220
188221
```js run
189-
function showMessage(from, *!*text = "no text given"*/!*) {
222+
function showMessage(from, *!*text = "текст не добавлен"*/!*) {
190223
alert( from + ": " + text );
191224
}
192225

193-
showMessage("Ann"); // Ann: no text given
226+
showMessage("Аня"); // Аня: текст не добавлен
194227
```
195228
229+
<<<<<<< HEAD
196230
Now if the `text` parameter is not passed, it will get the value `"no text given"`
197231
198232
Here `"no text given"` is a string, but it can be a more complex expression, which is only evaluated and assigned if the parameter is missing. So, this is also possible:
233+
=======
234+
Теперь, если параметр `text` не указан, его значением будет `"текст не добавлен"`
235+
236+
В данном случае `"текст не добавлен"` это строка, но на её месте могло бы быть и более сложное выражение, которое бы вычислялось и присваивалось при отсутствии параметра. Например:
237+
>>>>>>> translate examples
199238
200239
```js run
201240
function showMessage(from, text = anotherFunction()) {
@@ -220,7 +259,7 @@ For instance, an explicit check for being `undefined`:
220259
function showMessage(from, text) {
221260
*!*
222261
if (text === undefined) {
223-
text = 'no text given';
262+
text = 'текст не добавлен';
224263
}
225264
*/!*
226265

@@ -232,8 +271,13 @@ function showMessage(from, text) {
232271
233272
```js
234273
function showMessage(from, text) {
274+
<<<<<<< HEAD
235275
// if text is falsy then text gets the "default" value
236276
text = text || 'no text given';
277+
=======
278+
// Если значение text ложно, тогда присвоить параметру text значение по умолчанию
279+
text = text || 'текст не добавлен';
280+
>>>>>>> translate examples
237281
...
238282
}
239283
```
@@ -269,17 +313,17 @@ function checkAge(age) {
269313
*/!*
270314
} else {
271315
*!*
272-
return confirm('Do you have permission from your parents?');
316+
return confirm('А родители разрешили?');
273317
*/!*
274318
}
275319
}
276320

277-
let age = prompt('How old are you?', 18);
321+
let age = prompt('Сколько вам лет?', 18);
278322

279323
if ( checkAge(age) ) {
280-
alert( 'Access granted' );
324+
alert( 'Доступ получен' );
281325
} else {
282-
alert( 'Access denied' );
326+
alert( 'Доступ закрыт' );
283327
}
284328
```
285329
@@ -295,7 +339,7 @@ function showMovie(age) {
295339
*/!*
296340
}
297341

298-
alert( "Showing you the movie" ); // (*)
342+
alert( "Вам показывается кино" ); // (*)
299343
// ...
300344
}
301345
```

0 commit comments

Comments
 (0)