Skip to content

Instantly share code, notes, and snippets.

@mikewilcox
Created February 20, 2012 19:05
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 mikewilcox/1870764 to your computer and use it in GitHub Desktop.
Save mikewilcox/1870764 to your computer and use it in GitHub Desktop.
Function Statements, Definitions, Literals, and Expressions
myArray.sort(function(a,b){
// compare a and b
});
(function(){
// called!
})();
function A(){} // 14 characters
var A = function(){}; // 20 characters
var A = function(){
// called
};
A();
var Z = function Y(){
console.log('Y/Z called');
}
Z(); // Y/Z called
Y(); // Error: Y is not defined
var once = 0;
var Z = function Y(arg){
console.log('called:', arg);
if(once) return;
once = 1;
Y('Y local'); // called: Y local
}
Z('Z'); // called: Z
function(){
// never called.
}
function A(){
// called!
}
A();
"use strict";
if(true){
function E(){
console.log('true E')
}
}
E(); // Error: in strict mode code, functions may be declared
//only at top level or immediately within another function
function A(){}
var A = somethingElse; // strict warning: redeclaration of function A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment