Skip to content

Instantly share code, notes, and snippets.

@n8kowald
Last active December 11, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n8kowald/4556515 to your computer and use it in GitHub Desktop.
Save n8kowald/4556515 to your computer and use it in GitHub Desktop.
Notes on the name of JavaScript syntax and also rules.
/* RULES */
- Variable and function declarations are hoisted (names are moved to the top of their current scope) by the JavaScript interpreter.
- Variable initialisations are not moved.
- Only functions create new scope
- Function Declarations are officially prohibited within non-function blocks (such as if)
var a; // variable declaration
a = 1; // variable initialisation
- The function name (if any) of a function expression is not visible outside of it’s scope.
- The function name of a function declaration is visible within it’s scope and the scope of it’s parent
- Now in practice, generally you want to put your var declarations at the top of the function, since that is where they end up anyway.
/* NAMES */
Function Declaration
--------------------
function bar() {
return 3;
}
Function Expressions
--------------------
//anonymous function expression
var a = function() {
return 3;
}
//named function expression
var a = function bar() {
return 3;
}
//self invoking function expression
(function sayHello() {
alert("hello!");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment