-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoutput.js
More file actions
297 lines (244 loc) · 5.18 KB
/
Copy pathoutput.js
File metadata and controls
297 lines (244 loc) · 5.18 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//! EASY
// Question - 1
// console.log(5 + "3");
// // Question - 2
// const arr = [1, 2, 3];
// arr.push(4);
// console.log(arr);
// // Question - 3
// let a;
// // a='sec'
// console.log(a);
// // Question - 4
// console.log(typeof null);
// // Question - 5
// let b = 2;
// b += 3;
// console.log(b);
// // Question - 6
// let x = 10;
// function y() {
// return x;
// }
// console.log(y());
// // Question - 7
// const greeting = "Hello, world!";
// console.log(greeting.length);
// // Question - 8
// console.log(2 + "2");
// // Question - 9
// let name = "Alice";
// console.log(`Hello, ${name}!`);
// // Question - 10
// console.log([1, 2, 3].indexOf(2));
//! MEDIUM
// Question - 1
// let x = function() {
// return 10;
// }();
// console.log(x);
// Question - 2
// const obj = {
// name: "Alice",
// greet: function() {
// console.log(`Hello, ${this.name}!`);
// }
// };
// const greet = obj.greet;
// greet();
// Question - 3
// let arr = [1, 2, 3, 4, 5];
// let newArr = arr.filter(num => num > 2);
// console.log(newArr);
// Question - 4
// function add(a, b) {
// return a + b;
// }
// console.log(add(2, '3'));
// Question - 5
// let obj = { a: 1, b: 2 };
// let newObj = { ...obj, c: 3 };
// console.log(obj);
// console.log(newObj);
// Question - 6
// const nums = [1, 2, 3, 4];
// const result = nums.map(num => num * 2).reduce((a, b) => a + b);
// console.log(result);
// Question - 7
// function outer() {
// let count = 0;
// return function inner() {
// count++;
// return count;
// };
// }
// const counter = outer();
// console.log(counter());
// console.log(counter());
// Question - 8
// let person = { name: "Bob" };
// Object.freeze(person);
// person.age = 30;
// console.log(person);
// Question - 9
// let numbers = [1, 2, 3, 4, 5];
// let [first, ...rest] = numbers;
// console.log(rest);
// Question - 10
// async function fetchData() {
// return "data";
// }
// fetchData().then(data => console.log(data));
// Question - 11
// const sameerPromise = new Promise((resolve, reject) => {
// Math.random() * 10 < 5 ? resolve(1) : reject(0);
// });
// sameerPromise.then(res => console.log("resolve with :", res)).catch(err => {
// console.log("reject with :", err);
// });
//! HARD
// Question - 1
// How do you create and dispatch custom events in JavaScript?
// Question - 2
// Question - 3
// Question - 4
// Question - 5
// Question - 6
// Question - 7
// Question - 8
// Question - 9
// Question - 10
//! SCOPE CHAIN!
// Question - 1
// function outer() {
// let x = 10;
// function inner() {
// console.log(x);
// }
// return inner;
// }
// const innerFunc = outer();
// innerFunc();
// Question - 2
// function createCounter() {
// let count = 0;
// return function() {
// count++;
// return count;
// };
// }
// const counter = createCounter();
// console.log(counter());
// console.log(counter());
// Question - 3
// function outer() {
// let x = 1;
// function inner() {
// let x = 2;
// console.log(x);
// }
// inner();
// console.log(x);
// }
// outer();
// Question - 4
// function foo() {
// console.log(a);
// var a = 1;
// console.log(a);
// }
// foo();
// Question - 5
// let x = 10;
// function outer() {
// let x = 20;
// function inner() {
// console.log(x);
// }
// return inner;
// }
// const innerFunc = outer();
// innerFunc();
// Question - 6
// function outer() {
// let x = 1;
// return function() {
// console.log(x);
// };
// }
// const innerFunc1 = outer();
// const innerFunc2 = outer();
// innerFunc1();
// innerFunc2();
// Question - 7
// function foo() {
// console.log(a);
// let a = 1;
// }
// foo();
// Question - 8
// function outer() {
// let x = 1;
// function inner() {
// let y = 2;
// console.log(x + y);
// }
// return inner;
// }
// const func = outer();
// func();
// Question - 9
// function foo() {
// console.log(a);
// var a = 1;
// function bar() {
// console.log(a);
// var a = 2;
// }
// bar();
// }
// foo();
// Question - 10
// function createFunction() {
// let x = 10;
// return function() {
// console.log(x);
// };
// }
// let func1 = createFunction();
// let func2 = createFunction();
// func1();
// func2();
// Question - 11
// let a = 10;
// var b = 20;
// const c = 11
// b = 14;
// a = 12;
// var b = 55; // var can reassign and rediclare as well
// // let a =77 // you can reassign let but cannot rediclare
// // c= 787 //you cannot reassign or redeclare const variable
// console.log(a, " / ", b, " / ", c);
// function functionScopeExample() {
// var x = 10;
// if (true) {
// var x = 20; // Same variable, due to function scope
// console.log(x); // 20
// }
// console.log(x); // 20
// }
// // console.log(x); // x is not defined
// functionScopeExample();
//loop issue with var
// for (var i = 0; i < 4; i++) {
// setTimeout(() => {
// console.log(i);
// }, 1000);
// }
let x = 10;
let y = x++;
console.log(x);
console.log(y);
// let x = 10;
// x++;
// console.log(x);