Skip to content

Commit 52beff7

Browse files
committed
global variable defined with var will become window variable
1 parent e5f8d1f commit 52beff7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Global Scope.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<body>
5+
6+
<h2>JavaScript Scope</h2>
7+
8+
<p>A GLOBAL variable can be accessed from any script or function.</p>
9+
10+
<p id="demo"></p>
11+
12+
<script>
13+
var carName = "Volvo";
14+
myFunction();
15+
16+
function myFunction() {
17+
document.getElementById("demo").innerHTML = "I can display " + carName;
18+
}
19+
</script>
20+
21+
</body>
22+
23+
</html>

0 commit comments

Comments
 (0)