-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.Spread&Rest.js
152 lines (117 loc) · 3.16 KB
/
5.Spread&Rest.js
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
// Normal function
function sumOfElement(a,b){
return a+b
}
console.log(sumOfElement(10,40,50,60)) // In C language we get error becouse of the argus are not eqal tothe paramter
// --- Rest parameter ---
function sumOfElement(...a){ //...a is a rest parameter
return a.reduce((acc,el)=> acc+el)
}
console.log(sumOfElement(10,40,50,60))
console.log(sumOfElement(10,40,50,60,50))
console.log(sumOfElement(10,40,50,60,50,56,366,567))
// // Spread syntax
// //marge array
// let arr1 = [10,20]
// let arr2 = [30,40]
// let arr3 = [50,60]
// let margeArray = [...arr1 ,...arr2,...arr3]
// // marge object
// let obj1 = {
// a:10,
// b :20
// }
// let obj2 = {
// a:30,
// b :40
// }
// let margeObj = {...obj1,obj2}
// //Creating capies
// let arr = [10,30]
// let copyArr = [...arr]
// arr.push(30)
// console.log("Initial array",arr)
// console.log("copy arr",copyArr)
// //Destrucuring
// //array
// let numbers = [10,20,30]
// let [a,b,c] = numbers
// console.log(a)
// console.log(b)
// console.log(c)
// //object
// let person = {
// id : 300,
// salary:30000
// }
// let {id,salary} = person
// //modules
// //m1
// let username1 = "surya"
// //export
// export default username1
// //main.js
// import username1 from './m1.js'
// //--------------------
// //person.js
// class Person {
// constructor(id,name,city){
// this.name = name
// this.id = id
// this.city = city
// }
// printData(){
// console.log("name",this.name)
// console.log("id",this.id)
// }
// }
// export default Person
// // main.js
// import Person from "./person.js" // name must be the class name
// var resultValue = new Person(2334,"Vishwa","HYD")
// //import {YourChoosenName} from "./location.js"
// //for this we can export
// //export Person = () => {
// // logic
// //}
// // Default export | import Person from './person.js'
// // Default export | import prs from './person.js'
// // named export | named export | import {smth} from './unility.js'
// // named export | import {smth as Smth } from './unility.js'
// // named export importing every thing from file | import * as bundled from './unility.js'
// //******* CLASS ********
// class Human {
// constructor( ) {//constructor
// this.gender = "Male"
// }
// printGender( ){ //method
// console.log(this.gender);
// }
// }
// class Person extends Human( ){
// constructor ( ) {
// super (); //To access the base class
// this.name = 'vishwa';
// }
// printMyName ( ){
// console.log ( this.name )
// }
// }
// const person = new Person( );
// person.printMyName()
// person.printGender()
// //let & const this are newly implemented in ES6
// //let is like var
// // const is like constant //once assign no modifiy
// var myName = 'Vishwanath'
// console.log(myName)
// myName = "Manu"
// console.log(myName)//Name is changed
// let MyName1 = "Ramu"
// console.log(MyName1)
// myName1 = "Ramesh"
// console.log(myName)
// //const
// const myName2 = 'Ramu Kumar'
// console.log(myName2)
// //myName2 = 'Ramu' Here to