This seems to be easy question, but I can’t find an answer for this..
For example if I have the following object:
var a = {
foo : "FOO",
bar : "BAR"
}
Now, if I want to list properties of the objec, I should do the following :
for( var b in a ) {
// do something
}
or, I can do this :
for( b in a ) {
// do something
}
But, which is the difference beetween these methods? Why to use “var” or why not to use “var” in for in loop?
If you use a variable that has not been declared before without prepending
var, you create a global variable.However, there is no difference between
and