Demystifying JavaScript Variable Scope and Hoisting

It’s worth making the point that you shouldn’t rely on hoisting behaviour in your coding style. It’s worth understanding it, but actually scripting in a way that relies on it is a recipe for much confusion. A call to a function should always come after its declaration.