I am picking up maintenance of a project and reading code:
I see two methods of variable declaration. Can someone explain what the difference between the first and second line means?
To me, I am reading that in javascript, the var keyword is optional. in the first line, they have declared two new variables and initialized them. In the second line, they have declared two new varialbes but not have initialized them. Should I take anything more from this?
aURL = ""; msgNb = 1;
var mode, param, counter;
Unless all these variables are inside a function they’re all globals, the first two are assignments which I would guess because they were previously declared, otherwise it may be shortened to
The unassigned ones have an undefined value by default.
You should always use the
varkeyword to keep the variable within the same function scope and not force it to become an implicit global, otherwise you could run into issues with duplicate variable naming and assignment.