-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-Es6.js
50 lines (31 loc) · 1.15 KB
/
2-Es6.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
const numbers = [89, 35, 98, 12];
const student = {
name: 'Saki Khan',
age: 32,
movies: ['king khan', 'Dhaka Mast']
};
/* ----------------------------------------------- */
// 1. template string
const about = `My Name is ${student.name} age of ${student.age} has number ${numbers[2]} also liked movies ${student.movies[0]}`;
console.log(about)
/* ----------------------------------------------- */
// 2. arrow function
const getFiftyFive = () => 55; /* 1. No parameter arrow function */
const addSixtyFive = num => num + 65; /* 2. Single parameter arrow function */
const isEven = x => x % 2 == 0;
const addThree = (x, y, z) => x + y + z; /* 3. Multiple parameter arrow function */
const doMath = (num1, num2) => { /* 4. Multiline arrow function */
const sum = num1 + num2;
return sum;
}
/* ----------------------------------------------- */
// 3. spread operator
const originalNumbers = [...numbers];
// create a new array from an older array and add an element
const currentNumbers = [...numbers, 55];
numbers.push(99);
numbers.push(99);
numbers.push(99);
console.log(numbers);
console.log(originalNumbers);
console.log(currentNumbers);