forked from kangax/jstests
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction_statements_test.html
More file actions
46 lines (40 loc) · 1.31 KB
/
function_statements_test.html
File metadata and controls
46 lines (40 loc) · 1.31 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
if (true) {
function f(){ return 1; }
}
else {
function f(){ return 2; }
}
document.write(f() + '<br>');
document.write((typeof foo) + '<br>'); // "undefined"
if (true) {
// once block is entered, `foo` becomes declared and available to the entire scope
function foo(){ return 1; }
}
else {
// this block is never entered, and `foo` is never redeclared
function foo(){ return 2; }
}
document.write((typeof foo) + '<br>'); // "function"
if (true) {
function foo(){ return 1; }
}
document.write(foo + '<br>');
function bar(){ return 1; }
if (true) {
// overwritting with function statement
function bar(){ return 2; }
}
function bar(){ return 3; }
document.write(bar()); // 1 in FF<= 3, 2 in FF3.5 and later
</script>
</body>
</html>