Repository navigation
Expand file tree
/
Copy pathNotes.txt
More file actions
527 lines (367 loc) Β· 11.4 KB
/
Copy pathNotes.txt
File metadata and controls
527 lines (367 loc) Β· 11.4 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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
var let const
const :- fixed value
Types of console
console.log("hi")
console.info("hi") // is me and console.log me koi differnce nahi hota bus kisi kisi browser me i icon aata hai
console.warn("hi")
console.error("hi")
console.table({name: "Aakash"})// isme object ki jarurat hai
// Prompt alert // ye humesha STRING me value leta hai
let nm = prompt("name ?")
console.log(nm)
// Is ko string se number yani INT me convert karne ke 3 tarike hai
1. parseInt(nm)
2. Number(nm)
3.let nm = +prompt("name ?")
// let age = prompt("age batao")
if (age === null){ // agar cancel par clik kiya tho
console.log("abe cancel daya ")
}
else
{ if (age.trim() === ""){ // agar sapce ke saath kuch likha ho ( a ) tho ye trim kar dega
console.log(`bhai sahi se likh le `)
}
// Data Types
int,float,String,boolean
// array
array ek se jada chizo k liye hota hai
["AAKASH","RAN","ANKUR"]
object ek bande ki kai saari cheejo k liye hota hai
{
name:"AAKASH",
class :"JS"
}
undifine
var a;
//NAN - koi number ke saath aisa operation kiya jo ho nahi skta to NAN milta hai
12*"AALASJ" =
Infinity = 1/0
// relative and primitive datatyes in JS
refrence - array objects funtions
primitive - number booleans Strings null undined NAN Infinity Sumbol Big INT
primitive - jinki value direct copy kar sate hai
refrence - jinki value direct copy nahi kar saktea hai
typeof 12 :- kisi ka bhi type dekha na ho tho uske aaga typeof likh do
.slice(2,6)
.split("")
.replace("love","study at")
.includes("love")
Comparison Operators
== === != !== > < >= <=
//== not strict compare NEVER USE THIS
//==== Strict compare ALWAYS USE THIS
// != NEVER USE THIS
// !== ALWAYS USE THIS
Logical Operators
&& || !
// true && true = true //username === exist && password === userpassword
// false && true = false
// true && false = false
// false && false = false
// true || true = true
// true || false = true
// false || true = true
// false || false = false
! not :- ulta karta hai true ko false and false ko true
Ternary Operator
// condition ? doThis : doThat // is me 1st condition hota hai uske baad agar wo condition true ho tho ? ke baad wala chalta hai, false ho tho : ke baad wala
25>33 ? console.log("Ha 25 bada hai "):console.log("nahi bada nahi hai ")
Type CHecking Operator
// Typeof
//instanceof
String Operator
// + (for concatenation)
"AAKASH"+"TIWARI"
// Nullish Coalescing Operator
// ?(fallback only when null / undefined)
// Variable hoisting in JS
// hoisting ka matlab hai ki variable ko banane se pahle bhi use kiya jaa sakta hai
// hoisting me aapka variable toot jata hai
// intialization wohi rehta hai jaha variale tha
// ab aapka variable error nahi deta kyuki wo humesha use hone se phale exist kr rha tha
// hoisting let ke saath work nahi karta
///###### Loops $ Conditionals in Javascrpit
//if else
// truthy and falsy
// 0 "" false NaN null undefined document.all
// kuch bhi dikhe -> true
Loops
for(start;end;change)
while :- tab tak chalo jab tak condition true hai
start
while(end){
////Your code
//change
}
example
let i =1;
while(i<11){
console.log("hello")
i++;
}
// do while
// let i=1
// do {
// console.log("1")
// i++
// }while(1<10)
// --- Recursion In JS
===> funtions calling in itself
EXAMPLE
// function abcd(){
// console.log("hey")
// abcd()
// }
// abcd()
// Continue in JS
continue ka simple meaning hai:
Current iteration ko skip karo aur next iteration par chale jao.
// funtion in JS
====> aapka code jo turant nahi chalega tab chalega jab aap bole ge ki chalo
aap us code ko kitni bhi baar chala sakte ho
kisi kaam ko repat karna ho ya fir jo baar baar ho rha hai use specific time par karna ho tho funtion ka use karte hai
EXAMPLE
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) // is arguments ke help se hum values ko access kar sakete ye 2nd way hai
[0] is tarah se bhi hum values ko access kar sakte hai
}
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
// 1. why we use function
code ko reuse karne mein help karta hai, function ko hum jab chaye tab chala sakte hai
// parameters and arguments in funtion
function abcd(age, name ){
// parameter
}
abcd(12,vicky) // arguments
// rest parameter
function abcd(a,b,...c){ // is me b ke aage ke c tak sub ek array me chale jayenge
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
a() // function me hum is difine hone se phale bhi use kar sakte hai
function a(){
console.log(
"aakash"
)
}
// 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]
// function Types
[Classic function, Nested function(funtion within function// function ke ander function), Scope Chain in JS]
// 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;
},
)();
// More Functions in JS -[Arrow Function. Fat Arrow, Anonymousm, Higher Order, Callback,First class, Pure Function, Impure Function]
// Arrow Function :- normal
Eg:-
let function a(){
console.log("Aakash")
}
// 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(){})
// First class
### Pure Function
A **pure function** always gives the same output for the same input and does not modify anything outside its scope.
// 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
// impure function
same input = diffrent output ho sakta hai
side effect hosakta hai
// Closure -> ek function hai jo return karta hai function but
returning function jo hai wo parent function ka koi variable use kar gaaa
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
*/
// ======================================Return ==============================================
π₯ return kya karta hai?
return function ke andar ka result function ke bahar bhejta hai.
return = function ka result bahar bhejna + function ko wahi stop kar dena. π§
JavaScript mein return ko function ke bahar use nahi kar sakte. β
return 10;
Function ke bahar β SyntaxError
return ka purpose hi hai function se value bahar bhejna aur function ko stop karna.
// =================+++++++++++++++++++++ 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]*/
matalb arr[5] ye bus 1 array ho ga [5]
NewArray(5) 5 length honge [0,1,2,3,4]
// 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]
// 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();
1οΈβ£ Object Literal β {}
let obj = {
name: "aakash",
age: 25,
email: "aakash@gmail.com"
}
Isko Object Literal bolte hain.
Yaha tum object banate waqt hi properties de rahe ho:
obj.name // "aakash"
obj.age // 25
2οΈβ£ new Object()
let obj2 = new Object();
Ye bhi ek empty object banata hai.
Ab properties baad me add kar sakte ho:
obj2.name = "aakash";
obj2.age = 25;
obj2.email = "aakash@gmail.com";
Ab obj2 bhi almost obj jaisa hi ho gaya.
π₯ Main difference
let obj = {} let obj2 = new Object()
Object Literal Object Constructor
Short & simple Thoda lengthy
Most commonly used Rarely needed
Properties directly likh sakte ho Baad me bhi add kar sakte ho
// Nested Object
let obj={
name:"aakash",
socials:{
instagram:"_aakash7781",
facebook:"aakash",
}
}
console.log(obj.socials)