-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08Eight.js
78 lines (61 loc) · 1.25 KB
/
08Eight.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
// Task1
let name1="Tejas"
let age=19
console.log(`My name is ${name1} and age is ${age} !`);
// Task 2
let str=`Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet.
`
console.log(str);
// Task 3
let arr=[1,2,3,4,5,6]
let [a,b]=arr;
console.log(a,b);
// Task 4
let book={
title: "Atomic Habits",
author: "James clear",
year: 1986
}
let {author , title}=book;
console.log(title," written by ",author);
// Task 5
let arr1=[1,2,3,4,5,6,7]
let arr2=[...arr1,8,9,10]
console.log(arr2);
// Task 6
let arr3=[1,2,3,4,5,6,7,8,9,10]
let res=arr3.reduce((acc,curr)=>acc+curr,0)
console.log(res);
// Task 7
let par=function(num1,num2=1){
return num1*num2;
}
console.log(par(5,6));
console.log(par(5));
// Task 8
// In this we have written variables outside ,
// we can also use inside the object with same variable name
const first="Tejas"
let last="Dherange"
const names={
// first:"Tejas",
// last:"Dherange",
first,
last,
greet:function(){
return (` my full name is ${this.first} ${this.last}`);
}
}
console.log(names);
console.log(names.greet());
// Task 9
const key1="name"
const key2="age"
const obj={
[key1]:"Tejas",
[key2]:19
}
console.log(obj);
console.log(obj.name);