What's the difference between defining a variable with 'var' before, versus defining without it?
ex.
var s = 5;
Vs.
s = 5;
Printable View
What's the difference between defining a variable with 'var' before, versus defining without it?
ex.
var s = 5;
Vs.
s = 5;
This may not be the complete reason, but declaring with the var insures it is local to the proceedure, defining it without var may take on the instance of a variable at a higher level that has the same name.
Yep. With var, it's local, without var if undefined, it's global. I personally dislike declaring variables like that, I think it's bad practice.