variable scope
It's probably obvious to most of you that the following code writes "two" to the screen:
function changeIt() {
number = "two";
}
var number = "one";
changeIt();
document.write(number);And that if you declare the variable with
var inside the function, it'll write "one" instead:
function changeIt() {
var number = "two";
}
var number = "one";
changeIt();
document.write(number);( Here's where it gets a little weird...Collapse )