-
Notifications
You must be signed in to change notification settings - Fork 0
/
variable.html
48 lines (31 loc) · 847 Bytes
/
variable.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>
<head>
<title>Varibles</title>
</head>
<body>
<h1>Variables</h1>
<script>
//Write javascript between here..
var aVariable = "hello I am a String";
var yetAnotherVarible = 3.5;
//Do we need the var for variable assigment to work
itWorks = "Why do we need the var keyword?";
//apparently not!
alert (itWorks);
/*If you're in the global scope then you do not need the var keyword.
However:
If you're in a function then "var" will create a local variable,
"no var" will look up the scope chain until it finds the variable
or hits the global scope (at which point it will create it):
*/
function myFunction () {
itWorks = "Confusing!";
}
myFunction();
alert (itWorks);
// This is confusing ... I would argue, just use the var keyword as a habit to avoid conusion.
//..and here.
</script>
</body>
</html>