-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay19Destruturing.html
48 lines (43 loc) · 1.4 KB
/
Day19Destruturing.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DAY 19</title>
</head>
<body>
<script>
let des=['ponmani','venkatesan','software engineer']
let [firstname,lastname,profile]=des;//destructuring
console.log(firstname);
let [fname,lname]='ponmani venkatesan'.split(' ');
console.log(lname);//venkatesan
let strat=['hello','come','lets','play']
let [hey, ,ok]=strat;
console.log(ok);//skips second word
let[mars,...rest]=strat;
console.log(rest[0]);//come
console.log(rest[1]);//lets
console.log(rest[2]);//play
//object destruturing
let job = {
position:"frontend",
salary:"20k",
locations:'chennai'
}
let {position,salary,locations}=job;
console.log(position);//frontend
console.log(locations);//chennai
let mahabrath={
first:"arjunan",
second:'krishna',
third:'karnan'
}
function truth({first,second="ponmani",third}){
console.log("inside funtion",second);// krishna overrides ponmani, if value for second not found
// then it take ponmani
}
truth(mahabrath);
</script>
</body>
</html>