4545<!-- <img class="slide-image" showInPresentation="true" src="imgs\pic04.png" style="top:42.60%; left:9.51%; width:37.91%; z-index:-1" /> -->
4646
4747
48- <!-- attr: { showInPresentation:true, hasScriptWrapper:true } -->
48+ <!-- attr: { showInPresentation:true, hasScriptWrapper:true, style :"font-size:0.9em" } -->
4949<!-- # Functions in JavaScript -->
5050- Functions are small named snippets of code
5151 - Can be invoked using their identifier (name)
7575 }
7676 ```
7777
78- ` ` ` js
79- function printMsg(msg){
80- console.log(msg);
81- }
82- ` ` `
78+ ` ` ` js
79+ function printMsg(msg){
80+ console.log(msg);
81+ }
82+ ` ` `
8383
8484<!-- attr: { class: ' slide-section demo' , showInPresentation: true , hasScriptWrapper: true } -->
8585<!-- # Functions in JavaScript
8686## [Demo]() -->
87- <!-- < img class = " slide-image" showInPresentation= " true" src= " imgs\p ic05.png" style= " top:32.44%; left:31.50%; width:46.43%; z-index:-1" / > -->
8887
8988
9089
@@ -102,10 +101,9 @@ function printMsg(msg){
102101- Functions in JavaScript are ** First- class objects **
103102 - They can be assigned to variables and properties, passed as arguments and returned by other functions
104103 - They have properties of their own
105- - ` length` , ` caller ` , ` callee ` , ` name` , ` apply` , ` call` , ` bind` and more
104+ - ` length` , ` name` , ` apply` , ` call` , ` bind` and more
106105
107106- Functions are one of the ** most powerful features** in JavaScript
108- - And one of the ** most important**
109107
110108` ` ` javascript
111109function max(arr){ /* ... */ }
@@ -161,12 +159,12 @@ var printMsg = new Function("msg", 'console.log("msg");');
161159```
162160- Since functions are quite special in JavaScript, they are loaded ** as soon as possible**
163161
164- <!-- attr: { showInPresentation:true, hasScriptWrapper:true } -->
162+ <!-- attr: { showInPresentation:true, hasScriptWrapper:true, style: "font-size:0.9em" } -->
165163# Function Declaration
166164- ** Function declarations** use the ` function ` operator to create a function object
167- - Functions created with a declaration are available anywhere in their scope
168- - No matter where they are declared
169- - This allows using a function on a line above the declaration itself
165+ - Functions created with a declaration are available anywhere in their scope
166+ - No matter where they are declared
167+ - This allows using a function above the declaration itself
170168
171169 - _ Example:_
172170
@@ -184,16 +182,15 @@ var printMsg = new Function("msg", 'console.log("msg");');
184182<!-- < img class = " slide-image" showInPresentation= " true" src= " imgs\p ic09.png" style= " top:55.54%; left:35.30%; width:30.34%; z-index:-1" / > -->
185183
186184
187- <!-- attr: { showInPresentation: true , hasScriptWrapper: true } -->
185+ <!-- attr: { showInPresentation: true , hasScriptWrapper: true , style : " font-size:0.9em " } -->
188186# Function Expression
189187- ** Function expressions** are created using the ** function literal**
190- - They are available in the code below the line they are **defined**
191- - And cannot be used from the code above
188+ - They are available in the code below they are **defined**
192189 - Can be invoked immediately
193- - The name of function expressions is optional
194- - If the name is missing the function is called **anonymous**
190+ - The name of function expressions is optional
191+ - If the name is missing the function is called **anonymous**
195192
196- - _Example:_
193+ - _Example:_
197194
198195 ```js
199196 var printMsg = function (msg ){
@@ -254,12 +251,6 @@ new Function([optional arguments], body);
254251<!-- attr: { class:'slide-section demo', showInPresentation:true, hasScriptWrapper:true } -->
255252<!-- # Function Constructor
256253## [Demo]() -->
257- <!-- <img class="slide-image" showInPresentation="true" src="imgs\pic11.png" style="top:51.22%; left:75.55%; width:27.55%; z-index:-1" /> -->
258- <!-- <img class="slide-image" showInPresentation="true" src="imgs\pic12.png" style="top:51.22%; left:12.12%; width:27.44%; z-index:-1" /> -->
259- <!-- <img class="slide-image" showInPresentation="true" src="imgs\pic13.png" style="top:7.91%; left:61.47%; width:31.74%; z-index:-1" /> -->
260- <!-- <img class="slide-image" showInPresentation="true" src="imgs\pic14.png" style="top:7.91%; left:21.24%; width:29.09%; z-index:-1" /> -->
261-
262-
263254
264255
265256<!-- section start -->
@@ -286,15 +277,15 @@ new Function([optional arguments], body);
286277<!-- attr: { id:'function-methods', class:'slide-section', showInPresentation:true, hasScriptWrapper:true } -->
287278<!-- # Function Methods -->
288279
289- <!-- attr: { showInPresentation:true, hasScriptWrapper:true } -->
280+ <!-- attr: { showInPresentation:true, hasScriptWrapper:true, style: "font-size: 0.9em" } -->
290281# Function Methods
291282- Functions have methods as well
292283 - ` toString() `
293284 - Returns the code of the functions as a string
294- - ` call(context, arg0, arg1, arg2, ...) `
285+ - ` call(context, arg0, arg1, ...) `
295286 - Invokes the function with ` this ` set to ` context ` and the given args: ` arg0 ` , ` arg1 ` , etc...
296287 - ` apply(context, [arg0, arg1, …]) `
297- - Invokes the function with ` this ` set to ` context ` and the arguments are given as an array ` [arg1, arg2 , …] `
288+ - Invokes the function with ` this ` set to ` context ` and the arguments are given as an array ` [arg0 , …] `
298289- Basically ` call ` and ` apply ` do the same
299290 - ` call ` gets the arguments separated by comma
300291 - ` apply ` gets the arguments as an array of objects
@@ -311,10 +302,6 @@ new Function([optional arguments], body);
311302 var numbers = [2 , 1 , 3 , 45 , 1 , 2 , 3 , 111 ];
312303 max = Math .max .apply (null , numbers);
313304 min = Math .min .apply (null , numbers);
314-
315- // easier using the spread operator:
316- max = Math .max (... numbers);
317- min = Math .min (... numbers);
318305 ```
319306
320307- ` Array#slice `
@@ -393,7 +380,6 @@ console.log(factorial(12)); //479001600
393380<!-- attr: { class:'slide-section demo', showInPresentation:true, hasScriptWrapper:true } -->
394381<!-- # Factorial
395382## [Demo]() -->
396- <!-- <img class="slide-image" showInPresentation="true" src="imgs\pic16.png" style="top:45%; left:60%; width:40%; z-index:-1" /> -->
397383
398384
399385<!-- attr: { showInPresentation:true, hasScriptWrapper:true, style:'font-size:0.9em' } -->
@@ -544,7 +530,7 @@ console.log(factorial2(5)); //logs 120 - correct
544530<!-- attr: { id:'nested-functions', class:'slide-section', showInPresentation:true, hasScriptWrapper:true } -->
545531<!-- # Nested Functions -->
546532
547- <!-- attr: { showInPresentation:true, hasScriptWrapper:true } -->
533+ <!-- attr: { showInPresentation:true, hasScriptWrapper:true, style: "font-size: 0.9em" } -->
548534# Nested Functions
549535- Functions can be declared everywhere in the JavaScript code
550536 - Even inside another function:
0 commit comments