-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotes.txt
More file actions
366 lines (257 loc) · 7.7 KB
/
Copy pathNotes.txt
File metadata and controls
366 lines (257 loc) · 7.7 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
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(){})