-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday8.js
More file actions
90 lines (66 loc) · 1.76 KB
/
day8.js
File metadata and controls
90 lines (66 loc) · 1.76 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
// Day 8: ES6+ features
// Activity 1: Template Literals
// Task 1
let name = "Nitika";
let age = 20;
const str = `name: ${name} age: ${age}`;
console.log(str); //output: name: Nitika age: 20
// Task 2
const str2 = `hello, nice to meet you
Myself nitika`;
console.log(str2); //output: hello nice t meet you
// Myself nitika
// Activity 2: Destructuring
// Task 3
const nums = [1,2,3];
const [first,second,third] = nums;
console.log(first,second); //output: 1 2
// Task 4
const book = {
bookName: 'The palace of illusions',
Author: 'Chitra Banerjee',
};
const { bookName, Author} = book;
console.log(bookName); // Output: The palace of illusions
console.log(Author); // Output: Chitra Banerjee
// Activity 3: Spread and Rest operators
// Task 5
const arr1 = [1,2,3];
const arr2 = [...arr1];
arr2.push(4,5);
console.log(arr2); //output: [1,2,3,4,5]
// Task 6
function sum(...args){
return args.reduce((e1,e2)=>{
return e1+e2;
});
}
console.log(sum(1,2,3,4)); //output: 10
// Activity 4: Default parametrs
// Task 7
function product(a,b=1){
return a*b;
}
const product1 = product(2,3);
const product2 = product(5);
console.log(product1,product2); //output: 6, 5
// Activity 5: Enhanced object literals
// Task 8
let Name = "abc";
let Age = 18;
const obj = {Name,
Age,
introduce(){
console.log(`name: ${Name} age: ${Age}`)
}};
console.log(obj);
// Task 9
const propName1 = 'name';
const propName2 = 'age';
const propName3 = 'location';
const person = {
[propName1]: 'Alice',
[propName2]: 30,
[propName3]: 'New York'
};
console.log(person);