Javascript best practices

Hoisting

  • Declaring a variable using var, hoists var to the top of the closest function scope. It will not hoist the value.

    include example

mdnWebDocs

  • Anonymous function expressions

    include example

  • Named function expressions

    include example

  • Function declaration
    • All function declarations are effectively at the top of the scope.

      include example