Variable Scope

If a variable is declared inside of a function with var, then it is only locally available to that function. If it is declared without var then it is globally available.

If a variable is declared outside of a function with var, then it is not available inside of functions. If it is declared without var then it is globally available.

Examples

<script type="text/javascript">
var somevar = "i am locally available";
andanother = "i am global";

function foobar()
{
	var myvar = "i am local to this function";
	anothervar = "i am global";
}
</script>

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.