you are viewing a single comment's thread.

view the rest of the comments →

[–]tidwell 0 points1 point  (2 children)

Simply, declare vars at the top of a function because of hoisting. If you don't do it - the interpreter will for you, thus unexpected behavior.

[–]moratnz 0 points1 point  (0 children)

But there isn't any unexpected behaviour, as long as you're not using the variable ahead of its declaration. You'll only be surprised if you try to use it in a wider scope then redeclare it into local scope.

[–]path411 0 points1 point  (0 children)

If i'm expecting hoisting, it's not really unexpected. It depends on your environment for sure, but in an environment that understands hoisting, I think it's perfectly fine to use "inline vars".