Created
January 29, 2013 21:05
-
-
Save yangsu/4667863 to your computer and use it in GitHub Desktop.
JavaScript Funtions Example
This file contains 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
foo(1, 2, 3); // Works fine because we declared function using | |
// the function literal at the bottom | |
bar(1, 2, 3); // => ReferenceError: bar is not defined | |
// The functions name is optional | |
// Here we are storing an anonymous function in a variable bar | |
var bar = function (a, b, c) { | |
// ... | |
}; | |
// functions can be stored | |
var obj = { | |
baz: function () { | |
}, | |
// you may use the optional name if recursion is needed | |
fib: function fibbinator (n) { | |
// ... | |
return fibbinator(n-1) + fibbinator(n-2); | |
} | |
}; | |
function foo (a, b, c) { | |
// You can nest functions | |
function innerFoo() { | |
// ... | |
} | |
return innerFoo(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment