As far as I know variables declared inside a function are local variables (using var keyword or not).
If so then why does this output 5? Shouldn't I get a ReferenceError when calling func2 because x is only known to func1?
<script>
function func1(){
x = 5;
}
function func2(){
document.write(x);
}
func1();
func2();
</script>
letorvar- Patrick Evansval. Otherwise they're global. - Iván Nokonoko