-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_functions.js
More file actions
78 lines (57 loc) · 1.57 KB
/
04_functions.js
File metadata and controls
78 lines (57 loc) · 1.57 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// 1 Функции
// Function Declaration
// function greet(name) {
// console.log('Привет, ', name)
// }
// Function Expression
// const greet2 = function greet2(name) {
// console.log('Привет 2, ', name)
// }
// greet('Васек')
// greet2('Серега')
// console.log(typeof greet)
// console.dir(greet)
// 2 Анонимные функции
// let counter = 0
// const interval = setInterval(function() {
// if (counter === 5) {
// clearInterval(interval) //clearTimeout
// } else {
// console.log(++counter)
// }
// }, 1000)
// 3 Стрелочные функции
// function greet(nameA) {
// console.log('Привет, ', nameA)
// }
// const arrow = (nameA, age) => {
// console.log('Привет, ', nameA, age)
// }
// const arrow2 = nameA => console.log('Привет, ', nameA)
// // arrow2('Sergey')
// const pow2 = num => {
// return num ** 2
// }
// const pow3 = num => num ** 2
// console.log(pow3(5))
// 4 Параметры по умолчанию
// const sum = (a = 2, b = a * 2) => a + b
// console.log(sum())
// function sumAll(...all) {
// let result = 0
// for (let num of all) {
// result += num
// }
// return result
// }
// const res = sumAll(1, 2, 3, 4, 5)
// console.log(res)
// 5 Замыкания
// function createMember(nameA) {
// return function(lastName) {
// console.log(nameA, lastName)
// }
// }
// const logWithLastName = createMember('Sergey')
// console.log(logWithLastName('Bagdasaryan'))
// console.log(logWithLastName('Terentyev'))