-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJS_15c_script_functions.html
More file actions
50 lines (35 loc) · 1.63 KB
/
Copy pathJS_15c_script_functions.html
File metadata and controls
50 lines (35 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script>
"use strict";
// https://learn.javascript.ru/function-basics
function showMessage(from, text) { // параметры from, text
from = "** " + from + " **"; // здесь может быть сложный код оформления
alert(from + ': ' + text);
}
showMessage('Маша', 'Привет!');
showMessage('Маша', 'Как дела?');
/////////// Параметры копируются в локальные переменные функции.
function showMessage(from, text) {
from = '**' + from + '**'; // меняем локальную переменную from
alert( from + ': ' + text );
}
var from = "Тоня";
showMessage(from, "Привет-привет");
alert( from ); // старое значение from без изменений, в функции была изменена копия
/////////////////
function showMessage(from, text) {
if (text === undefined) {
text = 'текст не передан';
}
alert( from + ": " + text );
}
showMessage("Оля", "Привет!"); // Оля: Привет!
showMessage("Оля"); // Оля: текст не передан
</script>
</body>
</html>