A global variable exists through the entire program. If it's set in one function, it still has that value in another function.
Example global and local variable in javascript
<script>
var glb_test="Global";
function fun1()
{
var loc_test="Local ";
alert("Local Variable : "+loc_test);
alert("Global Variable : "+glb_test);
}
function fun2()
{
alert("Global Variable : "+glb_test);
alert("Local Variable : "+loc_test); //It show "Uncaught ReferenceError: loc_test is not defined" error
}
</script>
Example Program:- (Editor)
Editor is Loading...
Advertisement
0 comments:
Post a Comment