-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
109 lines (94 loc) · 1.98 KB
/
functions.js
File metadata and controls
109 lines (94 loc) · 1.98 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
*
### Catagories of Functions
**1. Synchronous Functions** {.fragment }
:::block
1. Function Declaration
2. Function Expression
3. Anonymous Functions
4. Arrow Functions
5. Curried Function
6. Closure
7. IFFE
{.fragment .current-only }
:::
**2. Async Functions** {.fragment }
:::block
1. Callbacks
2. Promises
3. Generator
4. Async / Await
5. Async Generator
{.fragment .current-only }
:::
**2. Object Oriented Functions** {.fragment }
:::block
1. Constructor
2. Class
<!-- Add Callback and -->
{.fragment .current-only }
:::
*/
/**
** function
*/
function firstFunction(params) {
console.log("hello " + params);
}
firstFunction("hello")
/**
** Arrow functions
*/
// single line
() => console.log("single");
// multiline
() => {
console.log("multiline");
}
// named arrow function
const name = (params) => {
console.log(params,"named");
}
/**
** Immediately Invoked Function Expressions (IFFY)
* http://adripofjavascript.com/blog/drips/an-introduction-to-iffes-immediately-invoked-function-expressions.html
*/
(function () {
var foo = "bar";
// Outputs: "bar"
console.log(foo);
})();
// ReferenceError: foo is not defined
console.log(foo);
/**
** Event Loop
* 1. Arrays & Memory Heap
* 2. Stack
* 3. Queue
* 4. Call Stack & Callback Queue
* https://blog.sessionstack.com/how-javascript-works-event-loop-and-the-rise-of-async-programming-5-ways-to-better-coding-with-2f077c4438b5
*
*/
/**
** Asynchronous Code
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous
* 1. Callbacks
* 2. Promises
* 3. Async/Await
* 4. Async Generators
*/
/**
** callbacks
https://www.dashingd3js.com/lessons/javascript-callback-functions
*/
function callback(x) {
console.log(x);
}
function callbackFunction(var1, var2, callback1, callback2) {
callback1(var1);
callback2(var2);
}
callbackFunction( 1, 2, // var1, var2
function (x) { console.log(x); }, // callback1
function (x) { console.log(x); } // callback2
);