As a rule of thumb: ALWAYS define your variables at the top of your desired scope. If you are using ‘use strict’; at the top of your script files (or within your functions), an error will be thrown if you try using a variable before it has been defined.
Most Javascript linters like Jshint will complain if you haven’t defined ‘use strict’ anyway, so provided you’re applying best practices it should be impossible to use variables before they are defined.
Everything after the first sentence describes why the first sentence is wrong...
4
u/rooktakesqueen Mar 09 '15
Everything after the first sentence describes why the first sentence is wrong...