CommentMar 16, 20173
The spec is not going to forbid using var the way you did. It's a matter of preference. I prefer my vars declared right around where they're used, and definitely within the same block. Before JS got block-scoped variables with "let", the advice to not declare vars inside blocks may have made sense, since doing so would give other developers the wrong idea about the vars' scope. But now, I would go ahead and keep the declaration (using let , not var ) inside the if block. PS: foo is going to be undefined, not null, if the condition is false; null !== undefined