-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobalVariable.html
47 lines (42 loc) · 1.1 KB
/
globalVariable.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Global Variable in JS</title>
</head>
<body>
<h1>Global Variable in JS</h1>
<script>
// Global variable in Js
// 1. declaring variable outside function
var value= 500;
document.write(value);
function a()
{
document.writeln(value);
}
// 2. using window object
function b()
{
window.data= 600;
}
function c()
{
document.writeln("variable declaration using window object : ")
document.writeln(window.data); ///accessing data
}
//3. variable declared outside the function is added in the window object
var key =800;
function d()
{
document.writeln(window.key);
}
//calling the functions
a();
b();
c();
d();
</script>
</body>
</html>