Hmm. That could be it; but it still seems to directly contradict their own advice. After all, the variable declaration is still hoisted before the if check, isn't it?
My point is that their advice says it should be the same: "Assign variables at the top of their scope.". The top of names scope is the top of the function. Therefore their advice would proscribe moving the assignment to the top of the function.
I'm not arguing about whether it's a good idea or not, I'm just trying to understand what they are advocating, since the statement and the example seem to be at odds, unless I am misunderstanding it.
3
u/pimlottc Mar 27 '15
Hmm. That could be it; but it still seems to directly contradict their own advice. After all, the variable declaration is still hoisted before the if check, isn't it?