Created
June 24, 2018 17:56
-
-
Save sevperez/06c02d783d382fe2a43559482a5e9d03 to your computer and use it in GitHub Desktop.
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 definition and invocation | |
| function speak(string) { | |
| console.log(string); | |
| } | |
| speak("Hello"); // logs "Hello" | |
| // Store in a variable | |
| var talk = speak; | |
| talk("Hi"); // logs "Hi" | |
| // Pass as an argument to a function | |
| // Return from a function | |
| function functionReturner(fn) { | |
| return fn; | |
| } | |
| var chat = functionReturner(talk); | |
| chat("Good Morning"); // logs "Good Morning" | |
| // Store in a data structure | |
| var myFuncs = [talk]; | |
| myFuncs[0]("Good Afternoon"); // logs "Good Afternoon" | |
| // Owns properties | |
| talk.myProperty = "bananas"; | |
| console.log(talk.myProperty); // logs "bananas" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment