-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2 variables Differences.html
More file actions
86 lines (67 loc) · 1.53 KB
/
2 variables Differences.html
File metadata and controls
86 lines (67 loc) · 1.53 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
<!-- 1st Var -->
<script>
var y="bhargav";
document.write(y + "\n");
{
var y=543;
document.write(y + "\n");
}
document.write(y + "\n");
// output:bhargav 543 543
</script>
<!-- 2nd Const -->
<script>
const x='hello';
document.write(x + "\n");
{
const x='namaste';
document.write(x + "\n");
}
document.write(x + "\n");
// output:hello namaste hello
</script>
<!-- 3rd example -->
<script>
const author='bhargav';
document.write(author);
{
let author='sandanala';
document.write(author);
}
document.write(author);
// output:prints nothing
</script>
<!-- 4th example -->
<script>
const author='bhargav';
console.log(author);
{
var author='bodybuilder';
console.log(author);
}
console.log(author);
// output:Uncaught SyntaxError: Identifier 'author' has already been declared
</script>
<!-- 5th example -->
<script>
const gothamCity;
document.write(gothamCity);
// output:Uncaught SyntaxError: Missing initializer in const declaration
</script>
<!-- Example 6 -->
<script>
let a = 543;
console.log(a);
let a="bhargav";
console.log(a);
// output:Uncaught SyntaxError: Identifier 'a' has already been declared
</script>
<!-- but the same identifier when enclosed in closure produces no Error -->
<script>
let a = 543;
console.log(a);
{let a="bhargav";
console.log(a);
}
// output:543 bhargav
</script>