Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ba2605

Browse files
authored
Add files via upload
1 parent 9ac04da commit 3ba2605

File tree

3 files changed

+227
-0
lines changed

3 files changed

+227
-0
lines changed

assets/callbacks.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
'use strict';
3+
4+
// Example #1
5+
// const btn = document.getElementById('btn');
6+
// btn.addEventListener('click', () => {
7+
// console.log('CLICKED');
8+
// });
9+
10+
// Example #2
11+
// const arr = [1,2,3,4,5];
12+
// const double = arr.map(el => el * 2);
13+
// console.log('DOUBLED', double);
14+
15+
// Example #3
16+
// const parent = callback => {
17+
// // What's the "typeof callback"?
18+
// console.log('AT START');
19+
// setTimeout(() => {
20+
// callback();
21+
// }, 2000);
22+
// console.log('AT END');
23+
// };
24+
25+
// const child = () => {
26+
// console.log('I AM CHILD');
27+
// };
28+
29+
// parent(child);
30+
31+
// Example #4 - passing arguments to callback
32+
// const target = (callback, arg) => {
33+
// console.log('AT START');
34+
// setTimeout(() => {
35+
// callback(arg);
36+
// }, 2000);
37+
// console.log('AT END');
38+
// };
39+
40+
// const func = number => {
41+
// console.log('CALLING CHILD WITH NUMBER:', number);
42+
// };
43+
44+
// target(func, 10);
45+
}

assets/hoisting.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
'use strict'
3+
4+
/*
5+
* Function Hoisting
6+
*/
7+
8+
// Exercise #1
9+
// abc();
10+
// function abc() {
11+
// console.log('INSIDE FUNCTION ABC');
12+
// }
13+
14+
// xyz();
15+
// var xyz = function() {
16+
// console.log('INSIDE FUNCTION XYZ');
17+
// };
18+
19+
// Exercise #2
20+
// function foo1() {
21+
// function bar() {
22+
// return 3;
23+
// }
24+
// return bar();
25+
// function bar() {
26+
// return 8;
27+
// }
28+
// }
29+
// console.log(foo1());
30+
31+
// Exercise #3
32+
// function foo2(){
33+
// var bar = function() {
34+
// return 3;
35+
// };
36+
// return bar();
37+
// var bar = function() {
38+
// return 8;
39+
// };
40+
// }
41+
// console.log(foo2());
42+
43+
// Exercise #4
44+
// console.log(foo3());
45+
// function foo3(){
46+
// var bar = function() {
47+
// return 3;
48+
// };
49+
// return bar();
50+
// var bar = function() {
51+
// return 8;
52+
// };
53+
// }
54+
55+
// Exercise #5
56+
// function foo4(){
57+
// return bar();
58+
// var bar = function() {
59+
// return 3;
60+
// };
61+
// var bar = function() {
62+
// return 8;
63+
// };
64+
// }
65+
// console.log(foo4());
66+
67+
/*
68+
* Variable Hoisting
69+
*/
70+
71+
// Exercise #1
72+
// arr = [10,20,30];
73+
// console.log(arr);
74+
// var arr;
75+
76+
// console.log(obj);
77+
// var obj = { a: 10, b: 20 };
78+
79+
// Exercise #2
80+
// console.log(num1);
81+
// let num1 = 10;
82+
83+
/*
84+
* Variable and Function hoisting combined
85+
*/
86+
87+
// Exercise #1
88+
// function parent() {
89+
// function hoisted() {
90+
// return "I'm a function";
91+
// }
92+
// hoisted = "I'm a variable";
93+
// return hoisted();
94+
// }
95+
// console.log(parent());
96+
97+
// Exercise #2 (Tricky)
98+
// function parent() {
99+
// var hoisted = "I'm a variable";
100+
// function hoisted() {
101+
// return "I'm a function";
102+
// }
103+
// return hoisted();
104+
// }
105+
// console.log(parent());
106+
107+
// Exercise #3
108+
// function func() {
109+
// function foo() { };
110+
// return foo;
111+
// foo = 10;
112+
// foo = 1;
113+
// }
114+
// console.log(typeof func());
115+
116+
// Exercise #4
117+
// function func() {
118+
// return foo;
119+
// foo = 10;
120+
// var foo = 1;
121+
// function foo() { };
122+
// }
123+
// console.log(typeof func());
124+
}

assets/scope.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Global scope variable available throughout the application.
2+
// Try doing console.log(globalVar) in callbacks.js or closures.js
3+
const globalVar = 100;
4+
5+
{
6+
'use strict';
7+
8+
// Exercise #1
9+
// const firstLocalFunction = () => {
10+
// const localVar = "I am a local variable";
11+
// console.log('INSIDE FIRST LOCAL FUNCTION', localVar, globalVar);
12+
// };
13+
14+
// firstLocalFunction();
15+
16+
// Exercise #2
17+
// const secondLocalFunction = () => {
18+
// // can use the same variable name here because of local scoping
19+
// const localVar = 10;
20+
// const nestedFunction = () => {
21+
// const nestedVar = "I am a nested variable";
22+
// console.log('INSIDE NESTED FUNCTION', nestedVar, localVar, globalVar);
23+
// };
24+
25+
// // nestedVar is not visible here
26+
// nestedFunction();
27+
// };
28+
29+
// secondLocalFunction();
30+
31+
// localVar defined inside the functions isn't visible here
32+
33+
// Exercise #3
34+
// const myFunction = () => {
35+
// const localVar = 10;
36+
37+
// if (localVar === 10) {
38+
// const innerVar = 100;
39+
// console.log('INSIDE IF BLOCK', localVar, innerVar);
40+
// }
41+
42+
// console.log(innerVar);
43+
// };
44+
45+
// myFunction();
46+
47+
// Exercise #4
48+
// const trickFunction = () => {
49+
// const arr = [10, 12, 15, 21];
50+
// for (var i = 0; i < arr.length; i++) {
51+
// setTimeout(function() {
52+
// console.log('Index: ' + i + ', element: ' + arr[i]);
53+
// }, 3000);
54+
// }
55+
// };
56+
57+
// trickFunction();
58+
};

0 commit comments

Comments
 (0)