-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
431 lines (324 loc) Β· 9.01 KB
/
Copy pathscript.js
File metadata and controls
431 lines (324 loc) Β· 9.01 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
// var a =12;
// let b = 13;
// sconst discount =100
// console.log(a)
// const { availableMemory } = require("node:process");
// const { log } = require("node:console")
// types of console
// console.log("hi")
// console.info("hi")
// console.warn("hi")
// console.error("hi")
// console.table({name: "Aakash"})
// let nm = prompt("name ?")
// console.log(nm)
// DATA TYPES
// var a;
// console.log(a)
// var a = [1,2,3,4]
// var b=a;
// b.pop()
// console.log(b)
// let a = prompt("name ?")
// alert(`HEY ${a}`)
// let a = prompt() // Prompt se jo bhi lo ge wo 1 String ban jaye ga This is the problem in JS
// console.log(typeof a)
// let count = 5;
// console.log(count);
// count = count-- + 5;
// console.log(count);
// var hello;
// hello()
// var hello =function(){
// console.log("hi")
// }
// console.log(a)
// let a =12
// if(0){
// console.log("Hello")
// }
// else{
// console.log("bye")
// }
// var a = 112>13?console.log("ha bhai bada hai "):console.log("nahi bhai")
// switch(8){
// case 1 : console.log("hey");break;
// case 2 : console.log("hey hey ");break;
// case 3 : console.log("hey hey hey ");break;
// case 4 : console.log("hey hey hey hey ") ;break;
// case 5 : console.log("hey hey hey hey hey ");break;
// default: console.log("1-5 daal")
// }
// FOR Loops
// for(start;end;change)
// for(let i=2;i<33;i++){
// console.log(i)
// }
// for(let i=121; i>12;i--){
// console.log(i)
// }
// for(let i=12;i>0;i--){
// if(i===5 || i===7){}//bypass
// else console.log(i)
// }
// --- Recursion In JS
// function abcd(){
// console.log("hey")
// abcd()
// }
// abcd()
// Continue in JS
// for(let i=1;i<10;i++){
// if(i===5)continue;
// console.log(i)
// }
// function in JS
// function khanakhaao(){
// console.log("step 1")
// console.log("step 2")
// console.log("step 3")
// console.log("step 4")
// }
// khanakhaao()
// parameter in JS
// function doSomething(name, age, email){
// // console.log(name,age,email)
// console.log(arguments)
// }
// doSomething("Aakash",25,"aakash@gmial.com")
// variable hoisting
// a() // ayise use nahi kar sakte variable me
// var a = function(){
// }
// a()// ayise use kar sakte ha
// function a(){}
// function name(){
// console.log("aakash")
// }
// name()
// parameters and arguments in funtion
// function abcd(age, name ){
// console.log(age,name)
// }
// abcd(12, "vicky") // arguments
// rest parameter
// function abcd(a,b,...c){
// console.log(a,b,c)
// }
// abcd(1,2,3,4,5,6,7,8,9)
// hoisting :- kisi cheeZ ke bane ke phale uska istmal kar pana
// function me hum is difine hone se phale bhi use kar sakte hai
// function a(){
// console.log(
// "aakash"
// )
// }
// var a=function(){
// console.log(
// "aakash"
// )
// }
// Error :- Uncaught TypeError: a is not a function
// function a(){} β poora function hoist β
// var a = function(){} β sirf a hoist, value initially undefined β
// - Paramertes in JS - [`required`, `destructured`, `rest`, `default`]
// required parameter
// function abcd(a,b,c,d){
// console.log(a,b,c,d)
// // agar aapne parameter banaaye and aapne unme arguments nahi bheje tho fir wo value parameter ki undifined ho jaayegi
// }
// abcd()
// default parameter
// function ab(a=0,b=0,c=0){ // ye ha par hum default values de salte hai other wise undifined aaye ga
// console.log(a,b,c)
// }
// ab(1,2)
// `destructured`, `rest`, ===> is ke like OOPS and object lage ga
// - Arguments in JS -[`positional`,`default`, `spread`]
// function ab(a=0,b=0,c=0,d=0){// default hai
// console.log(a,b,c,d)
// }
// ab(1,2,3,4) // ye [psitional hai]
// function ab(a=0,b=0,c=0,d=0){// default hai
// console.log(a,b,c,d)
// }
// let arr=[1,2,3,4] // ye hai spread
// ab(...arr) // ye [psitional hai]
// Nested Function
// function ab(){
// function cd(){
// console.log("ander ka chala cd")
// }
// cd()
// }
// ab()
// Scope chain
// let a=12 //global scope
// function abcd(){
// let b = 13;
// function df(){
// console.log(b)
// }
// }
// abcd()
// - Understanding Immediately Invoked Function Expression (IIFE)
// (function () {})()(
// // - function without name , this use to make private variable
// // example
// function () {
// let balance = 5000;
// },
// )();
// Fat Arrow Function
// let fnc = ()=>{
// console.log("Aaaaa")
// }
// fnc()
// Anonymous Function :- ek ayisa function jiska koi naam naa ho
// function() {
// console.log("Hello");
// }
// Higher Order Function
// 1. ek aisa fnc jo ki return karde ek aur funtion
// wo fnc accept karle ek aur fnc parameter main
// // 1.
// function abcd(){
// return function(){
// }
// }
//2.
// function ab(){
// }
// ab(function cd(){}) // ye he callback function bhi hai
// pure Function = ek aisa function jo ye 2 chiZe Follow karta hai
// same input hone par same output hota hai
// koi side effect nahi hoga
// let a = 12
// function ab(val){
// console.log(val+2)
// }
// ab(12) // is me ye bina a ko modifiy kiye output dega
// Impure Function :-
// An **impure function** changes external variables or depends on them.
// let a=12;
// function ab(val){
// a= Math.random()+val
// console.log(a)
// }
// ab(12)
// ab(12)
// ab(12)
// ab(12)
// Closure -> highr order function bhi hota hai
// function ab(){
// let a= 12;
// return function(){
// console.log(a)
// }
// }
// let fun= ab()
// fun()
/* π₯ Closure kya hai?
Jab ek inner function, apne outer function ke variables ko remember karta hai, even after outer function ka execution khatam ho gaya ho, usko Closure kehte hain.
Tere example mein:
ab()
β
βββ a = 12
β
βββ inner function
β
βββ remembers β a
*/
// =================+++++++++++++++++++++ Arrays +++++++++++++++++++++======================
// Ararys ->
// ek se jaada members rakhne ki jagah hote hai
// 0 1 2 3 4 5 6
// let arr = [671,902,3534,4534,5675,8996,4567]
// console.log(arr[5])
// How to create Arrays in JS
// let arr = []
// let arr2 = new Array()
/*[] β array banao
[5] β 5 ko value samjho
new Array() β empty array
new Array(5) β 5 length ka empty array
new Array(5,6) β [5,6]*/
// Understanding how to Accessing Elements in Array
// let arr = [1,2,3,4,5]
// console.log(arr[3])
// Function on Arrays -[push, pop , shift,unshift, indexof, array destructuring ,filter, some,
// map ,reduce ,spread operator, slice, reverse , sort, join, toString]
//------------Push
// let arr = [1,2,3,4,5,6]
// arr.push(5)
// console.log(arr) // Array ke END mein new value add karna. β
[1, 2, 3, 4, 5, 6, 5]
// ------------POP
// let arr = [1,2,3,4,5,6,7,8,9]
// arr.pop() // last wala remove ho jaye da is me 9 remove hua
// console.log(arr)
//------------Shift
// let arr = [1,2,3,4,5,6,7,8,9]
// arr.shift() // starting ki 1st value ko remove kar deta hai
// console.log(arr)
//------------UnShift
// let arr = [1,2,3,4,5,6,7,8,9]
// arr.unshift(0) // starting ki 1st me value ko add kar deta hai
// console.log(arr)
// //------------indexof
// let arr = [1,2,3,4,5,6,7,8,9]
// console.log(arr.indexOf(5) ) // Array ka index value batata hai
//------------array destructuring
// let arr = [1,2,3,4,5,6,7,8,9]
// let [a,,b]=arr;
//------------filter // ye new array banata hai or filter lagata hai is eg main ye 3 se chote value ko print kar rha (condtion ka use hota hai)
// let arr = [1,2,3,4,]
// let arr2 = arr.filter(function(val){
// return val<3
// })
// console.log(arr2)
//------------sum
// let arr = [1,2,3,4,5,6,7,8,9]
// let [a,,b]=arr;
// Iterating over Arrays using -[For loop , forEach-ye shirf array par chalta hai ]
// let arr = [1,2,3,4]
// for(let i = 0; i<4; i++){
// console.log(arr[i])
// }
// let arr = [1,2,3,4]
// arr.forEach(function(val){
// console.log(val)
// })
// -Understanding what are Object in JS
// [key-value pair]
// let obj ={
// // KEY VALUE
// name :"aakash",
// age :25,
// email:"aakash@gmail.com"
// }
// let obj2 =new Object();
// Creating Object, Accessing Properties, Deleting Property and Nested objects
// let obj = {
// name :"aakash"
// }
// Accessing
// console.log(obj[`name`]) // ye 2 tarika hai Access karne kaa
// console.log(obj.name)
//Deleting
// delete obj.name
// console.log(obj.name)
// // Nested Object
// let obj={
// name:"aakash",
// socials:{
// instagram:"_aakash7781",
// facebook:"aakash",
// }
// }
// console.log(obj.socials)
// Recognise How Objects Are Stored, Traverse Keys of an Object, Array as Object.
// Recognise How Objects Are Stored,
// {
// name:"aakash"
// age:27
// }