2011/1/14 Gary Katsevman <[email protected]>:
> The reason why he doesn't like putting the var in the for loops has to
> do with variable hoisting and non-block scope in javascript.
>    [code]
> He would rather people define the variable outside of the for loop so
> that people realize that the variable is still available after the for
> loop ends.
>   [code]
>
> Gary Katsevman

There are advantages and disadvantages of course. Some people find
it hard to maintain a large list of variables at the beginning of each function.
It also leads to unnecessary comments, for when the variable gets far
away from its point of usage you need to "introduce" it to the reader
beforehand.

Once you understood scope it's not that essential where you put
your variable declarations. Even if you made a mistake I find it
very easy to spot these kind of situations.

I agree with Garrett that it's more like a style preference.

Write code that looks unambiguous for you and others reading
your code. Nothing else matters.

- Balázs

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to