-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicJavaScript_4.js
More file actions
1962 lines (1734 loc) · 50.5 KB
/
Copy pathBasicJavaScript_4.js
File metadata and controls
1962 lines (1734 loc) · 50.5 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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Array and Arrays Functions:
*/
// Array:
/*
The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name, and has members for performing common array operations.
JavaScript arrays are resizable and can contain a mix of different data types. (When those characteristics are undesirable, use typed arrays instead.)
JavaScript arrays are not associative arrays and so, array elements cannot be accessed using arbitrary strings as indexes, but must be accessed using nonnegative integers (or their respective string form) as indexes.
JavaScript arrays are zero-indexed: the first element of an array is at index 0, the second is at index 1, and so on — and the last element is at the value of the array's length property minus 1.
JavaScript array-copy operations create shallow copies. (All standard built-in copy operations with any JavaScript objects create shallow copies, rather than deep copies).
*/
/*
A shallow copy of an object is a copy whose properties share the same references (point to the same underlying values) as those of the source object from which the copy was made. As a result, when you change either the source or the copy, you may also cause the other object to change too. That behavior contrasts with the behavior of a deep copy, in which the source and copy are completely independent.
A deep copy of an object is a copy whose properties do not share the same references (point to the same underlying values) as those of the source object from which the copy was made. As a result, when you change either the source or the copy, you can be assured you're not causing the other object to change too. That behavior contrasts with the behavior of a shallow copy, in which changes to nested properties in the source or the copy may cause the other object to change too.
*/
/*
1. () ==> Parenthesis / Parentheses /Round Brackets ==> Used For Methods ;
2. {} ==> Curly Brackets ==> Used To Set Scope ;
3. [] ==> Square Brackets ==> Used For Arrays ;
*/
/*
const myArr = [0,1,2,3,4,5,true,'Arafat',"Arfan"]
console.log(myArr["one"]);
const myHeros = ["Arafat","Arfan"]
const myArr2 = new Array(1,2,3,4,5)
console.log(myArr[0]);
console.log(myArr2[0]);
console.log(myHeros[0]);
//Array's Methods:
myArr.push(6) // Add in Array[in last positions]
myArr.pop() // remove in Array[in last positions]
myArr.unshift(9) // Add in Array[in first positions]
myArr.shift() // remove in Array[in first positions]
console.log(myArr);
console.log(myArr.includes(10)); //false
console.log(myArr.indexOf(10)); // -1{All time same}
console.log(myArr.indexOf(3)); // 3
const newArr = myArr.join() // convert into "array" to "string".
console.log(myArr);
console.log(newArr);
console.log( typeof newArr);
// slice, splice
console.log("A = ",myArr);
const myn1 = myArr.slice(1,3) // [1,2]{not include 0 and 3}(starting point-1,end point-2).
console.log(myn1);
console.log('B = ', myArr);
const myn2 = myArr.splice(1,3)
// ==> splice :
// [1,2,3]
// that means A=[0,1,2,3,4,5,true,'Arafat',"Arfan"]{Main}
// C = [0,4,5,true,'Arafat',"Arfan"]
// [1,2,3] ==>not includes in {main brance 'C'}
console.log('C = ', myArr);
console.log(myn1);
console.log(myn2);
if you know more about array's then click on this :
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
*/
/*
----------------------------- X ---------------------------
*/ // Array's Function:
const { useReducer } = require("react")
/*
Browser --> inspect --> Then ...
const Numbers = [1,2,3,4,5] =>undefined
=>Numbers (5) [1, 2, 3, 4, 5]
0: 11: 22: 33: 44: 5
length: 5
[[Prototype]]:
Array(0)at: ƒ at()
concat: ƒ concat()
constructor: ƒ Array()
copyWithin: ƒ copyWithin()
entries: ƒ entries()
every: ƒ every()
fill: ƒ fill()
filter: ƒ filter()
find: ƒ find()
findIndex: ƒ findIndex()
findLast: ƒ findLast()
findLastIndex: ƒ findLastIndex()
flat: ƒ flat()
flatMap: ƒ flatMap()
forEach: ƒ forEach()
includes: ƒ includes()
indexOf: ƒ indexOf()
join: ƒ join()
keys: ƒ keys()
lastIndexOf: ƒ lastIndexOf()
length:
0map: ƒ map()
pop: ƒ pop()
push: ƒ push()
reduce: ƒ reduce()
reduceRight: ƒ reduceRight()
reverse: ƒ reverse()
shift: ƒ shift()
slice: ƒ slice()
some: ƒ some()
sort: ƒ sort()
splice: ƒ splice()
toLocaleString: ƒ toLocaleString()
toReversed: ƒ toReversed()
toSorted: ƒ toSorted()
toSpliced: ƒ toSpliced()
toString: ƒ toString()
unshift: ƒ unshift()
values:
ƒ values()
with: ƒ with()
Symbol(Symbol.iterator): ƒ values()
Symbol(Symbol.unscopables): {at: true, copyWithin: true, entries: true, fill: true, find: true, …}
[[Prototype]]:
Objectconstructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ toString()
valueOf: ƒ valueOf()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter
__()__lookupGetter__: ƒ __lookupGetter
__()__lookupSetter__: ƒ __lookupSetter
__()__proto__: (...)get __proto__: ƒ __proto__()
length:
0name: "get __proto__"arguments: (...)
caller: (...)
[[Prototype]]:
ƒ ()[[Scopes]]: Scopes[0]set __proto__: ƒ __proto__()
length:
1name: "set __proto__"arguments: (...)caller: (...)
[[Prototype]]: ƒ ()apply: ƒ apply()arguments: (...)
bind: ƒ bind()
call: ƒ call()
caller: (...)
constructor: ƒ Function()
length:
0name: ""toString: ƒ toString()
Symbol(Symbol.hasInstance): ƒ [Symbol.hasInstance]()get arguments: ƒ arguments
()set arguments: ƒ arguments()
get caller: ƒ caller()
set caller: ƒ caller()
[[FunctionLocation]]: [[Prototype]]: Object[[Scopes]]: Scopes[0][[Scopes]]: Scopes[0]No properties
*/
const mc_heros = [ "Thor","Iron-man","SpiderMan"]
const dc_heros = [ "SuperMan","Flash","BatMan"]
mc_heros.push(dc_heros)
// mc_heros.concat(dc_heros)
// console.log(mc_heros);
// console.log(mc_heros[3][1]);
const allHeros = mc_heros.concat(dc_heros) // Finally 2 Arrays marges...
// console.log(allHeros);
const all_new_heros = [...mc_heros,...dc_heros] // ... ==>spread/ spread out==>all arrays are marged.
// console.log(all_new_heros);// Finally 2 Arrays marges...{same}
const another_array = [1,2,3,[4,5,6],7,[8,9,10],[11,12,[13,14,15],16,17],18,19,20]
const real_another_array = another_array.flat(Infinity) // ALL Arrays are marged in 1 Array.
// console.log(real_another_array);
// console.log(Array.isArray("Arafat"));
// console.log(Array.from("Arafat"));
// console.log(Array.from({name:"Arafat"})); //interesting;empty array given.
let score01 = 100
let score2 = 200
let score3 = 300
// console.log(Array.of(score01,score2,score3)); //setup elements. ==>[100,200,300]==>given like array.
/*
++++++++++++++++++++++++++ X +++++++++++++++++++++++++
*/
// Objects:
// singleton ==>Constructer
/*Syntax:
Object.create
*/
// Object Literals:
/*
Syntax:
let jsUser = {}
*/
const jsUser = {
/* By Default :
0:"Arafat"
"name":"Arafat" */
name:"Arafat",
"full name":"Al-Arafat Yeash",
age:26,
location:"Demra",
email:"arafatgoogle.com",
isLoggedIn:false,
lastLoginDays:["Monday","Saturday"],
// mySymbol:"myKey1" //Given as a String input ,not symbol.
[mySymbol]:"myKey1"
}
const mySymbol = Symbol("key1")
console.log([mySymbol]); // For Access to Symbol
/*
Firstly,Define Object...
Secondly,Define Symbol
let jsUserObj = {
==> mySymbol:"myKey1" //Given as a String input ,not symbol.
[mySymbol]:"myKey1"
const mySymbol = Symbol("key1")
console.log([mySymbol]);
}
That's it to all the process...
Source for "Symbol":
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Data_structures
*/
console.log(jsUser.email);
// console.log(jsUser[eamil]); //Syntax Error.
console.log(jsUser["eamil"]);
// console.log(jsUser.full name); //Got Error...
console.log(jsUser["full name"]);
console.log(jsUser["full name"]);
// Change inside the object values/properties.
jsUser.email = "arfangooglejsUser.com"
// Object.freeze(jsUser)
jsUser.email = "arfathfjffhufg.com"
console.log(jsUser);
//Object Inside of Function:
jsUser.greeting = function(){
console.log("Hello Js User.");
}
// console.log(jsUser.greeting); //BecauseOf -->Undefined / [Function( anonymous)]
// console.log(jsUser.greeting()); // Not a Functions
jsUser.greetingTwo = function(){
console.log(`Hello Js User, ${this.name}`);
}
console.log(jsUser.greeting());
console.log(jsUser.greetingTwo());
/*
Some Unnecessary things:
// myArray = ["H","i"]
// myArray[0]
// () $
*/
const tinderUser = new Object() //Empty Objects ==> This is a "Singleton~Objects."
/*
Or,
const tinderUser = {} //Empty Objects ==> This is a "Non-Singleton~Objects."
Same Things ,no changes
*/
// console.log(tinderUser);
const tinderUser1 = {} // ==>This is a " Non-Singleton~Objects."
tinderUser1.id = " 45374dfjghd"
tinderUser1.name = "Arafat"
tinderUser1.isLoggedIn = false
// console.log(tinderUser1);
console.log(Object.keys(tinderUser1)); //This given Output as an "[] ==>Array."
console.log(Object.values(tinderUser1));
console.log(Object.entries(tinderUser1)); //This given Output as an "[] ==>Array in array,each an every single data define as an array,,,like: [[],[],[],[]...]"
console.log(tinderUser1.hasOwnProperty('isLoggedIn'));
console.log(tinderUser1.hasOwnProperty('isLogged'));
/*
Now,
Objects in Objects: Below...
*/
const regularUser = {
email:"arafatabc59.com",
fullname:{ // objects inside an objects...
userfullname:{
firstname: " Arafat ",
lastname: " Yeash"
}
}
}
/*
console.log(regularUser);
console.log(regularUser.fullname);
console.log(regularUser.fullname.userfullname);
console.log(regularUser.fullname.userfullname.firstname);
console.log(regularUser.fullname.userfullname.lastname);
*/
const obj1 = {1:"a",2:"b"}
const obj2 = {3:"f",4:"k"}
// const obj3 = {obj1,obj2}
// const obj3 = Object.assign(obj1,obj2)
// const obj3 = Object.assign({},obj1,obj2) // ==>"{}" It is better to use in assign().
const obj3 = {...obj1,...obj2} //This is use to best...
// console.log(obj3);
/*
Object Documentation Source:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
*/
const users = [ // [] ==> This an Array.
{ // {} ==> This an Objects.
id:1,
email:"sb1fdsbdf.com"
},
{
id:2,
email:"sb2fdsbdf.com"
},
{
id:3,
email:"sb3fdsbdf.com"
},
]
console.log(users);
console.log(users[1].email);
// users[1].email
/*
Browser --> Inspect --> Console :
const obj1 = {1:"a",2:"b"}
==> undefined
==> obj1
{1: 'a', 2: 'b'}
1: "a"
2: "b"
[[Prototype]]:
Objectconstructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ toString()
valueOf: ƒ valueOf()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
__proto__:
(...)get __proto__: ƒ __proto__()
set __proto__: ƒ __proto__()
*/
/*
Advanced Object(JSON): Object de-structure and JSON API Intro :
*/
/*
de-structure /De-Structuring occurs 2 Things : i. Array ; ii. Objects
*/
/*
// Object De-Structure : Same Basic Of React.js ...
const course = {
coursename:"Js in Bangla",
price:"999Tk",
courseTeacher:"Arafat",
courseInstructor:"Yeash"
}
// course.courseTeacher ==> Please don't use,becauseof repeating " course.courseTeacher " writing again and again.
const {courseTeacher} = course ==> please use this,
// console.log(courseTeacher);
Or,
const {courseTeacher:instructor} = course ==>use this.
// console.log(instructor);
*/
/*
// Some React.js Basic:
const navbar = (props.company) => {
}
Or,
const navbar = ({company}) => {
}
navbar(company = "Arafat")
*/
/*
Now,
Some Basic Of " API or JSON " :
*/
/*
// This is an Syntaxical Error,becauseof "Inverted Comas("")" :
{
name:"arafat",
coursename:"Js Bangla",
price:"free"
}
// This is an Syntaxically Right,becauseof "Inverted Comas("")" :
{
"name":"arafat",
"coursename":"Js Bangla",
"price":"free"
}
*/
/*
For API Resource : https://randomuser.me/
For API Formate : https://jsonformatter.org/
*/
/*
// Some API Formate : Get Arrays in Objects,like this : -
[ // Arrays
{}, //objects
{}, //objects
{} //objects
]
*/
/*
// A Example/Model of API/JSON Formate :
{
"results": [
{
"gender": "female",
"name": {
"title": "Miss",
"first": "Jennie",
"last": "Nichols"
},
"location": {
"street": {
"number": 8929,
"name": "Valwood Pkwy",
},
"city": "Billings",
"state": "Michigan",
"country": "United States",
"postcode": "63104",
"coordinates": {
"latitude": "-69.8246",
"longitude": "134.8719"
},
"timezone": {
"offset": "+9:30",
"description": "Adelaide, Darwin"
}
},
"email": "jennie.nichols@example.com",
"login": {
"uuid": "7a0eed16-9430-4d68-901f-c0d4c1c3bf00",
"username": "yellowpeacock117",
"password": "addison",
"salt": "sld1yGtd",
"md5": "ab54ac4c0be9480ae8fa5e9e2a5196a3",
"sha1": "edcf2ce613cbdea349133c52dc2f3b83168dc51b",
"sha256": "48df5229235ada28389b91e60a935e4f9b73eb4bdb855ef9258a1751f10bdc5d"
},
"dob": {
"date": "1992-03-08T15:13:16.688Z",
"age": 30
},
"registered": {
"date": "2007-07-09T05:51:59.390Z",
"age": 14
},
"phone": "(272) 790-0888",
"cell": "(489) 330-2385",
"id": {
"name": "SSN",
"value": "405-88-3636"
},
"picture": {
"large": "https://randomuser.me/api/portraits/men/75.jpg",
"medium": "https://randomuser.me/api/portraits/med/men/75.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/men/75.jpg"
},
"nat": "US"
}
],
"info": {
"seed": "56d27f4a53bd5441",
"results": 1,
"page": 1,
"version": "1.4"
}
}
*/
/*
++++++++++++++++++++++++ X ++++++++++++++++++++++++++
*/
/*
FUNCTION :
*/
/*
// This is not a Function Definition or Syntax/Structure:
console.log("A");
console.log("R");
console.log("A");
console.log("F");
console.log("A");
console.log("T");
console.log("H");
console.log("E");
*/
/*
Basic Of Functions:
//Function's Definitions:
Type :- 01
function sayMyName()
{
console.log("A");
console.log("R");
console.log("A");
console.log("F");
console.log("A");
console.log("T");
console.log("H");
console.log("E");
}
// sayMyName ==> //This is function's reference,
sayMyName() // when "()" this function sign means execute.
*/
// Now,Real Function's Basics Structure :
// Type :- 02
function addTwoNum(num1,num2) {
// console.log(num1+num2);
}
// addTwoNum() //Output: NaN
addTwoNum(3,4) // OutPut: 7
// addTwoNum(3,"4") // What if? ==>34,because "4" is a string that's why js think 3 is also string,that how become =>34
// addTwoNum(3,"a") // What if? ==>3a,because "a" is a string that's why js think 3 is also string,that how become =>3a
// addTwoNum(3,null) // What if? ==>3
/*
Difference about "Parameters" and "Arguments" :
function addTwoNum2(num1,num2) ==> (num1,num2)--> Parameters
addTwoNum2(3,4) ==>(3,4)--> Arguments
*/
/*
// Type :- 03
function addTwoNum2(num1,num2) {
console.log(num1+num2);
}
addTwoNum2(3,4)
function addTwoNum3(num1,num2) {
console.log(num1+num2);
}
addTwoNum3(3,"4","a")
function addTwoNum4(num1,num2) {
console.log(num1+num2);
}
addTwoNum4(3,null)
function addTwoNum5(num1,num2) {
console.log(num1+num2);
}
*/
//Store In Variables:
// Type :- 04
const result1 = addTwoNum5(3,45)
console.log("Result: ",result1); //undefined
// Type :- 05
function addTwoNum6(num1,num2) {
// Not print anythings because not execute "console.log"
// but,if i do "console.log" then what?
let result2 = num1+num2
console.log("Arafat");
return result2
// console.log("Arafat");
// console.log("Arafat"); //The answar is :not print/execute this "console.log", because,"return" পরে কিছু লিখলে তা কখনোই "print" হয় না,"return"এর উপরে "console.log" থাকলে "print" হয় না।
}
const result2 = addTwoNum5(3,5)
console.log("Result: ",result2);
/*
// Extra : copy on "result2"
// Type :- 06
function addTwoNum6(num1,num2) {
let result3 = num1+num2
console.log("Arafat");
return result3
// console.log("Arafat");
}
const result3 = addTwoNum5(3,5)
console.log("Result: ",result3);
*/
// Type :- 07
function addTwoNum7(num1,num2) {
let result4 = num1+num2
return result4
// console.log("arafat");
}
// Type :- 08
const result5 = addTwoNum7(3,45)
console.log("Result: ",result5);
// Type :- 09
function addTwoNum8(num1,num2) {
let result6 = num1+num2
console.log("arafat");
return result6
}
// Type :- 10
const result7 = addTwoNum8(3,45)
console.log("Result: ",result7);
// Type :- 11
function addTwoNum9(num1,num2) {
// let result8 = num1+num2
// console.log("arafat");
// return result8
return num1+num2
}
const result8 = addTwoNum9(3,45)
console.log("Result: ",result8);
/*
// Type :- 12
function loginUserMessage(username) {
return ` ${username} Just Logged In.`
}
// loginUserMessage()
// loginUserMessage("Arafat")
// console.log(loginUserMessage("")); //no change
// console.log(loginUserMessage()); //undefined
// console.log(loginUserMessage("Arafat"));
*/
/*
// Type :- 13
function loginUserMessage1(username1) {
if (username1===undefined) {
console.log("Please Enter Your UserName");
return
return ` ${username1} Just Logged In.`
}
return ` ${username1} Just Logged In.`
}
// loginUserMessage1()
// loginUserMessage1("Arafat")
// console.log(loginUserMessage1("Arafat"));
// console.log(loginUserMessage1(""));
console.log(loginUserMessage1());
*/
/*
// Type :- 14 : Same Output:Type :-13
function loginUserMessage1(username1) {
if (!username1) {
console.log("Please Enter Your UserName");
return
}
return ` ${username1} Just Logged In.`
}
// loginUserMessage1()
// loginUserMessage1("Arafat")
// console.log(loginUserMessage1("Arafat"));
// console.log(loginUserMessage1(""));
console.log(loginUserMessage1());
// ("") ==> Empty String /(undefined)==> False Value.
*/
// Type :- 15
function loginUserMessage2(username2="Samy") {
if (!username2) {
console.log("Please Enter Your UserName");
return
}
return ` ${username2} Just Logged In.`
}
// loginUserMessage()
// loginUserMessage("Arafat")
// console.log(loginUserMessage2());
/*
// Type :- 16
function loginUserMessage2(username2="Samy") {
if (!username2) {
console.log("Please Enter Your UserName");
return
}
return ` ${username2} Just Logged In.`
}
// loginUserMessage()
// loginUserMessage("Arafat")
// console.log(loginUserMessage2());
console.log(loginUserMessage2("Arafat")); // override "Samy"
*/
// Type :- 17
function calculateCartPrice(num1) {
return num1
}
console.log(calculateCartPrice(2));
/*
Type :- 18
If ,
console.log(calculateCartPrice(200,400,53545,453,2425));
Then What ?
The Answar Is:
restOperator{...} / spreadOperator.
*/
function calculateCartPrice(...num2) {
return num2
}
console.log(calculateCartPrice(200,400,53545,453,2425));
// Type :- 19
function calculateCartPrice(val1,val2,...num3) {
return num3
}
console.log(calculateCartPrice(200,400,53545,453,2425));
/*
Type :- 20
//Objects:
const user = {
userName: "Arafat",
price:164
}
*/
function handleObject(anyobject) {
console.log(`UserName is ${anyoject.userName} and price is ${anyoject.price}`);
}
handleObject(user)
/*
Type :- 21
const user = {
userName: "Arafat",
prices:164 //if I replaces as "price" in "prices".....",handleObject(user) " // undefined
}
*/
function handleObject(anyobject) {
console.log(`UserName is ${anyoject.userName} and price is ${anyoject.price}`);
}
handleObject(user) // undefined
// Type :- 22 :Same OutPut:Type:-21
handleObject({
userName:"sam",
price:356
})
// Type :- 23
// Arrays:
const myNewArray = [200,400,100,544]
function returnSecondValue(getArray) {
return getArray[1]
}
console.log(returnSecondValue(myNewArray));
// Or,
console.log(returnSecondValue([
200,400,100,544 //same output
])); // Override "myNewArray"
// ---------------------x-----------------------
/*
Scope ==>
{
} :
*/
let a = 10
const b =20
var c = 30
d = 40
/*
console.log(a);
console.log(b);
console.log(c);
console.log(d);
*/
if (true)
{
let a = 10
const b =20
var c = 30
d = 40
}
/*
console.log(a);
console.log(b);
console.log(c);
console.log(d);
*/
/*
// Block Scope:
if (true) {
let a = 10
const b =20
var c = 30
d = 40
}
*/
/*
// Global Scope:
//var c = 300 //don't use var
let f = 300
if (true) {
let f = 10
console.log("Inner: ",f);
}
console.log("Outer:",f);
*/
/*
For Loop Syntax:
for (let index = 0; index < array.length; index++) {
const element = array[index];
}
*/
// Scope level and mini hoisting in javascript:
//This is some Kind of "Closure" :
function one() {
const username = "Arafat"
function two() {
const website = "Youtube"
console.log(username);
}
// console.log(website); // This is Getting "Error",because This "console.log(website)" inside the "function two(){}".
two(); // But if I comment Out Of "two()" function then not execute of "console.log(username)".
}
one();
/*
Or,
Same Things of "if-else":
*/
if (true) {
const username = "Arafat"
if (username==="Arafat") {
const website = " youtube"
console.log(username+website);
}
// console.log(website); // This is Getting "Error",because This "console.log(website)" inside the "second scope{}".
}
// console.log(username); // This is Getting "Error",because This "console.log(username)" inside the "first scope{}".
// Interesting Example :
//Type :- 01
function addOne(num) {
return num + 1
}
addOne(5)
/*
Same Thing Different Type:
*/
//Type :- 02
const addTwo = function (num) {
return num + 2
}
addTwo(5)
//Type :- 03
addThree(5)
console.log(addThree(5));
function addThree(num) {
return num + 1
}
//Type :- 04
addFour(5) // Now given to the error... Because This Problem seems to "Hoisting"
const addFour = function(num) {
return num + 2
}
// .......................... X ............................
// "This" and Arrow Function:
/*
//Type :- 01
const user = {
username:"arafat",
price: 999tk,
welcomeMessage: function () {
console.log(this);
console.log(` ${this.username},Welcome To Website,This price is
${this.price} `);
console.log(this);
}
}
user.welcomeMessage() //This "user.welcomeMessage()" for arafat
user.username = "Sam"
user.welcomeMessage() //This "user.welcomeMessage()" for sam
console.log(this); // Refer as empty objects,lile :- {}
*/
//Type :- 02
function chai() {
console.log(this);
}
chai()
//Type :- 03
function chai1() {
let username = "arafat"
console.log(this);
// console.log(this.username); // Given "Undefined"
}
chai1()
//Type :- 04 {"This" Function Execute Through "Arrow" Function}
const chai1 =function () {
let username = "arafat"
console.log(this);
// console.log(this.username); // Given "Undefined"
}
chai1()
//Type :- 05 {"This" Function Execute Through "Arrow" Function}
// Arrow Function:()=> {}
const chai1 = ()=> {
let username = "arafat"
console.log(this);
// console.log(this.username); // Given "Undefined"
}
chai1()
//Type :- 05 {Explicity}
/*
const addTo = (num1,num2)=> {
return num1 + num2
}
console.log(addTo(3,4));
*/
//Type :- 06 {Implicity}
/*
const addToo = (num1,num2)=> num1 + num2
console.log(addToo(3,4));
*/
//Type :- 07 {Implicity}
/*
const addTo = (num1,num2)=> (num1 + num2) // This Technique needs for React.js
console.log(addToo(3,4));
*/
//Type :- 08 {Objects in "return"}
const addTo = (num1,num2)=> ({ username:"Arafat",username1:"Arfan",username2:"Yeash"})
//Type :- 09 {Objects in "return"}
/*
const myArray = [2,3,4,6,7]
// myArray.forEach(function () {} )
// myArray.forEach( () => {} )
// myArray.forEach( () => () ) // This is incorrect
*/