You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Links to subjections for detailed breakdown of each
55
55
56
-
---
56
+
----->
57
57
58
58
### What is Function?
59
59
60
-
A block of reusable code.
60
+
> "A block of reusable code." {.fragment .current-only }
61
61
62
-
---
62
+
:::block {.fragment .current-only }
63
+
There are two steps to this:
64
+
1. creating the function
65
+
2. using it / calling it.
66
+
67
+
:::
63
68
64
69
65
70
71
+
---
66
72
67
73
74
+
### First-class Functions
68
75
76
+
> "functions are first-class citizens, which means they are treated like any other variable. This is where JavaScript gets it's best features." {.fragment .current-only}
69
77
70
78
71
-
<!-- will be... automatically genrated from code file with a tool -->
79
+
:::block {.fragment .current-only }
80
+
As a first class citizen, functions can be used as:
81
+
1. callbacks in other function,
82
+
2. creating asynchronous operations,
83
+
3. preform recursion for iterative operations
84
+
85
+
:::
72
86
73
87
---
74
88
75
-
76
89
### Function Declaration
77
90
78
91
What a function declaration looks like:
@@ -87,42 +100,143 @@ Has the following Features:
87
100
88
101
**Block Syntax**, with `{}` at the begining and the end of the function and usually followed by a `;` {.fragment .current-only data-code-focus=1-3}
89
102
90
-
91
-
:::block
92
103
***Function** keyword
93
104
* Name of function, `add`
94
105
* Parameters `(param1, param2)`, which act as variables inside the functions definition.
95
106
{.fragment .current-only data-code-focus=1-1}
96
-
:::
97
107
98
108
**Return** keyword, ends the function
99
109
and the result is returned {.fragment .current-only data-code-focus=2-2}
100
110
111
+
---
112
+
113
+
114
+
### Using Functions
115
+
116
+
```JavaScript
117
+
add(1, 2) //return a value of 3
118
+
```
119
+
**Calling** the Function:
120
+
121
+
We pass *values*, `(1,2)`, into the **arguements**
122
+
{.fragment .current-only data-code-focus=1-1}
123
+
124
+
**Values of arguements** can be any type of variable, and because functions are *treated like variable*, you use can pass them into a **arguement** which is known as a **callback**.
125
+
{.fragment .current-only data-code-focus=1-1}
126
+
127
+
128
+
---
129
+
130
+
### Function Declaration - Node.js
131
+
132
+
```javascript
133
+
AAhoisted ="undeclared, hoisted";
134
+
varAAA="declared, not hoisted, var doesn't matter as much, let/const still better";
135
+
functionfunctionDeclaration() {
136
+
console.log(`\n Is DECLARATION hoisted: ${global.functionEXPRESSION}\n`);
137
+
}
138
+
varfunctionEXPRESSION=function () {
139
+
console.log(`\n Is EXPRESSION hoisted: ${global.functionEXPRESSION}\n`);
0 commit comments