This exercise show duplicated variable name in global and local:
- my_var1 declared and defined outside function as global variable
- my_var2 duplicated with local variable without defination.
- my_var3 duplicated with local variable, load value before use.
- my_var4 duplicated with local variable, load value after use
|
duplicated variable name in global and local |
<!DOCTYPE HTML>
<html>
<head>
<title>Mobile-Web-App</title>
<script>
var my_var1 = "my var 1";
var my_var2 = "my var 2";
var my_var3 = "my var 3";
var my_var4 = "my var 4";
var testjavascript = (function (){
console.log("Test Start");
var my_var2;
var my_var3 = "my var define inside function before use";
console.log("my_var1: " + my_var1);
console.log("my_var2: " + my_var2);
console.log("my_var3: " + my_var3);
console.log("my_var4: " + my_var4);
var my_var4 = "my var define inside function after use";
console.log("Test End");
});
console.log("testjavascript() run after document loaded.");
window.onload = testjavascript();
</script>
</head>
<body>
<h1>Mobile-Web-App</h1>
<h2>http://mobile-web-app.blogspot.com/</h2>
</body>
</html>
No comments:
Post a Comment