Created
February 20, 2012 19:05
-
-
Save mikewilcox/1870764 to your computer and use it in GitHub Desktop.
Function Statements, Definitions, Literals, and Expressions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myArray.sort(function(a,b){ | |
// compare a and b | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
// called! | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function A(){} // 14 characters | |
var A = function(){}; // 20 characters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var A = function(){ | |
// called | |
}; | |
A(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Z = function Y(){ | |
console.log('Y/Z called'); | |
} | |
Z(); // Y/Z called | |
Y(); // Error: Y is not defined |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(){ | |
// never called. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function A(){ | |
// called! | |
} | |
A(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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