Created
March 9, 2013 18:21
-
-
Save jescalan/5125130 to your computer and use it in GitHub Desktop.
Javascript function declaration
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
| // In this first example, I declare a function with what I call | |
| // the 'standard' syntax, which is what I have taught. Because of | |
| // this, I can make a call to the function before or after the declaration. | |
| say_hello(); // logs 'hello world!' | |
| function say_hello(){ | |
| console.log('hello world!'); | |
| } | |
| say_hello(); // logs 'hello world!' | |
| // In the second example here, I create a function by assigning an | |
| // anonymous function to a variable, then making a call on the variable. | |
| // This will throw an error unless the variable was defined in the right order. | |
| say_hello2(); // error: 'say_hello' is undefined | |
| var say_hello2 = function(){ | |
| console.log('hello world!'); | |
| } | |
| say_hello2(); // logs 'hello world!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment