-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
490 lines (360 loc) · 8.09 KB
/
Copy pathscript.js
File metadata and controls
490 lines (360 loc) · 8.09 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
console.log("hello nikunj");
var username="nikunj12345";
const password="12345";
//alert("welcome to javascript ");
//prompt("Enter your Name Using javascript");
console.log(username);
console.warn("dont give the another password other than saved");
console.log("Enter the password");
console.log(password);
console.error("wrong password");
var a=12.2;
var b=a;
const c=10;
var d=c;
var e = NaN;//not an number;
//window bucket from browser
var g=10;
if(g=>10)
console.log("its 10");
else
console.log("its smaller than 10");
for(var i=0;i<5;i++)
{
console.log("its javascript");
}
var h=5;
do{
console.log("its father");
}
while(h<5)
// function
function abcd()
{
if(h=>5)
console.log("its five");
else
{
console.log("its greater than 5");
}
}
abcd();
var abgh =function()
{
if(a == 12.2)
console.log("its 12.2");
else
console.log("its not ");
}
abgh();
//es6 function
var m =()=>
{
console.log("its fat arrow ");
}
m();
//fat arroe function
var gh=(ab)=>
{
console.log("its paramter"+" "+ab);
return ab;
}
gh(12);
// array
var user =["nikunj ","mans","digvijay","krishna"];
console.log(user[0]);
console.log(user);
var obj1={
name:"nikunj",
class:"ty.btech",
year:"3 rd year",
politics:"no politics",
};
console.log(obj1.name);
console.log(obj1.class);
console.log(obj1.year);
console.log(obj1.politics);
var obj2= new Object();
obj2 ={
name:"digvijay",
class:"ty.btech",
year:" 3 rd year",
};
console.log(" ");
console.log(obj2.name);
console.log(obj2.class);
console.log(obj1.year);
console.log(" ");
const {name:n}=obj2;//destructure of object for resuing the name of object properly
console.log(n);
// with parameter and return type ;
function userloggedin(ussssername)
{
if(!ussssername)
{
console.log("Enter valid user name")
return
}
return `${ussssername} just logged in `
}
const result=userloggedin("nikunj");
console.log("the user is",result);
//passing object as parameteer
const loggedin=
{
username:"nikunj",
age:21,
designation:"B.tech"
}
function logvalues(anyobject)
{
console.log(`username is ${anyobject.username} and the age is ${anyobject.age}`)
}
// function orobject(on) {
// Example usage of the 'on' object
//console.log(`usecase is ${on.usecase} and age is ${on.age}`);
// }
// orobject(obj2)
logvalues(loggedin)
//passing the array in function
const newarray=[100,200,300,400];
function returnthirdvalues(anyarray)
{
return anyarray[2]
}
console.log(returnthirdvalues(newarray));
// scope and hoisting
let num=10;
console.log(addonemore(num))
function addonemore(num)
{
return num+1
}
const addtwomore =function(num)
{
return num+2;
}
console.log(addtwomore(num))
//print the current date
let datetoday = new Date();
console.log(datetoday.toLocaleString())
// this keyword
console.log(this)
const vlogger={
user:"nikunj",
age:21,
desination:b.tech,
welcomemsg:function()
{
console.log(`the user is ${this.user} the age is ${this.age}`)
}
}
vlogger.welcomemsg()
vlogger.user="digvijay"
vlogger.welcomemsg()
function am()
{
let username="pranav"
console.log(this.username)
}
am()
const at=function()
{
let username="kanacha"
console.log(this.kancha)
}
at()
//fat arrow function
const dm =()=>{
let username="sahil"
console.log(this.username)
}
dm()
//implicit function
function adddone(num1,num2)
{
return num1+num2
}
console.log(adddone(7,7))
const addddone=(num1,num2)=>(num1+num2)
console.log(addddone(7,7))
const printobj=()=>(console.log({username:"hitesh"}))
printobj();
//iife immediate invoked function expressuion
// named iife
( function call()
{
console.log("DB connected")
}) ();
// unnamed iife
( (namelogin)=>{
console.log(`DB Connected ${namelogin}`)
})("pranav")
//loops
for(let index=0;index<10;index++)
{
const element=index;
if(index===5)
{
console.log("5 is the best number");
}
console.log(element);
}
for(let i=0;i<=10;i++)
{
console.log(`the outer loop ${i}`)
for(let j=0;j<=10;j++)
{
// console.log(`the inner loop ${j} the outer loop ${i}`)
//console.log(i+'*'+j+'='+i*j)
}
}
let thedate=Date();
console.log(thedate.toLocaleString());
let cross=["dighu",'nikunj','pranav']
for(let i=0;i<cross.length;i++)
{
const elem=cross[i];
//console.log(elem);
}
// for(let i=1;i<20;i++)
// {
// console.log(`the elem is ${i}`);
// // if(i==5)
// // {
// // break;
// // }
// // else{
// // continue;
// // }
// // }
// while loop
let ni=0;
while (ni<=10)
{
// console.log(`the index is${ni}`)
ni=ni+2;
}
// let amr=0;
// while(amr<cross.length)
// {
// const elem=cross[amr];
// console.log(elem);
// amr++;
// }
let score=11;
do{
console.log(`the score is${score}`)
}
while(score<=10)
// for of loop
const greetings="hello world";
for (const greet of greetings) {
console.log(`the elem is ${greet}`);
}
// unique value
const map =new Map();
map.set("in","india")
map.set("usa","usa")
console.log(map);
for (const [key,value] of map) { // array destructure to print
console.log(key,":-",value);
}
// object is not iteratale ,maps are iteratale ,object are not iteratable on for of
// for in loops
const obj={
cpp: "c++",
js: "javascript",
java:"java",
swift:"swift for apple "
}
// for in loops are for objects maps are not iteratable on object
for (const key in obj) {
console.log(`${key} for language shortcut ${obj[key]}`)
}
const arr3=["java","swift","c++","ruby"];
// for (const [key] in arr3) {
// console.log(`${arr3[key]}`);
// }
// // for in loops doesnt works on the maps iteration
// arr3.forEach(function(value){
// console.log(value);
// })
function print(value,index,arr){
console.log(value,index,arr);
}
arr3.forEach(print)
const coding =[
{
languagename:"java",
languagefilename:"java"
},
{
languagename:"javascript",
languagefilename:"js"
},
{
languagename:"c++",
languagefilename:"cpp"
}
]
// coding.forEach((item)=>{
// console.log(`${item.languagename}the filename is${item.languagefilename}`);
// })
// use of filter - directly return teh value
const arr4=[1,2,3,4,5,6,7,8]
// // const value=arr4.forEach(function (item){
// // console.log(item)
// // return item ;
// })
// console.log(value);
// not returrning the values
// filter for making the constions on array
// const newnums=arr4.filter(function(item) {
// return num>4
// })
// console.log(newnums);
// map condition
// const val1=arr4.map((num)=> num+10)
// console.log(val1);
// map chaining with filter left - to right passing with filter(true and false) only filtered true vale passes
const val2= arr4
.map((num)=>num*10)
.map((num)=>num+1)
.filter((num)=> num>=40)
console.log(val2)
//reduce method - have acculumlator ancurd value with comma with initial for one time then add sum in next accumulator
// const arr5=[1,2,3]
// const total=arr5.reduce(function(acc,cur){
// console.log(`the acc is${acc} the curr is${cur}`)
// return acc+cur;
// },8 ) // last one is intiail value for acuumulator
// console.log(total);
const shoppingcart=[
{
itemname:"webdevcourse",
price:15000
},
{
itemname:"data science",
price:12999
},
{
itemname:"ml",
price:1300
},
{
itemname:"mobile dev",
price:1000
},
]
const totalcart=shoppingcart.reduce((acc,item)=> acc+item.price,0)
console.log(`the value of ${totalcart}`);
const val1= arr4
.map((num)=>num*10)
.map((num)=>num+1)
.filter((num)=> num>=40)
console.log(val1)
// javascrpit is syncronus
// javascipt is single threaded
// javascript always found with its runtime environment