Forum Moderators: open
Let's say the first time I use the variable is in a loop. Is it correct to do:
for(var i=0;i<10;i++)
{
var someVar += 'hey'+i;
}
or should i do this:
var someVar = null;
for(var i=0;i<10;i++)
{
var someVar += 'hey'+i;
}
Also what if I do this:
if(someVar)
var anotherVar;
var anotherVar
Because, what if that if statement evaluates false and doesn't even get to the var. Should I do var afterwards jsut incase?
Thanks a lot for your help.
If you want a variable's initialization to be conditional, put it in a conditional statement; if you don't want its initialization to be conditional, don't.