Global scope and page scope
<html>
<head>
<title>Scope</title>
<script type="text/javascript">
if (typeof(message) != 'undefined')
message += " globalPrint";
function globalPrint() {
document.write(message);
}
</script>
<script type="text/javascript">
function global2Print() {
message += " global2Print";
document.write(message);
}
</script>
<script type="text/javascript">
message = "AAA";
function testScope() {
message += " in testScope()";
document.write(message);
}
</script>
</head>
<body onload="testScope();global2Print();globalPrint()">
<script type="text/javascript">
message += " embedded in page";
document.writeln(message);
</script>
</body>
</html>
Related examples in the same category