-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlet_vs_const.html
59 lines (51 loc) · 1.03 KB
/
let_vs_const.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
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
<head>
<title>let vs const</title>
</head>
<body>
<h2>let vs const</h2>
<p>You can't reassign const variable</p>
<script>
// with let variable
let software1 = {
name: 'Gmail',
company: {
name: 'Google'
}
};
software1.name = 'Apple';
console.log(software1);
/*
Result with let variable
company: {
name: "Google"
}
name: "Apple"
*/
software1 = { name : 'Hi'};
console.log(software1);
/* result
{name: "Hi"}
*/
// with const variable
const software2 = {
name: 'Gmail',
company: {
name: 'Google'
}
};
software2.name = 'Apple';
console.log(software2);
/*
Result with const variable
company: {
name: "Google"
}
name: "Apple"
*/
software2 = { name : 'Hi'};
console.log(software2); // get error "let_vs_const.html:49 Uncaught TypeError: Assignment to constant variable."
</script>
</body>
</html>