<html>
<head>
<title>Local Variable</title>
</head>
<body>
<p>The local variable website cannot be accessed from code outside the function:</p>
<p id="web"></p>
<script type="text/javascript">
myFunction();
document.getElementById("web").innerHTML =
"This is sample webste " + typeof url;
function myFunction() {
var url = "www.freetimelearning.com";
}
</script>
</body>
</html>
The local variable website cannot be accessed from code outside the function:
This is sample webste undefined
<html>
<head>
<title>Global Variable</title>
</head>
<body>
<p>A Global variable can be accessed from any script or function.</p>
<p id="web"></p>
<script>
var url = "www.freetimelearning.com";
myFunction();
function myFunction() {
document.getElementById("web").innerHTML =
"This is sample website " + url;
}
</script>
</body>
</html>
A Global variable can be accessed from any script or function.
This is sample website www.freetimelearning.com