Last active
August 26, 2018 10:08
-
-
Save travishen/22ea12502ddb6e8cf1b0bc3b2cfe4cba 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 Statement | |
| greet(); // hoisting | |
| function greet(){ | |
| console.log('hi'); | |
| }; | |
| // FUNCTION EXPRESSION (ANONYMOUS) | |
| anonymousGreet(); // undefined is not a function | |
| anonymousGreet; // undefined | |
| var anonymousGreet = function(){ | |
| console.log('hi'); | |
| }; | |
| // wrap in parentheses | |
| (function(){ | |
| console.log('hi'); | |
| }); | |
| // IMMEDIATELY INVOKED FUNCTION EXPRESSIONS (IIFE) | |
| var IIFEGreet = function(name){ | |
| return 'hi ' + name; | |
| }('John'); // hi John | |
| IIFEGreet; // hi John | |
| "hi John"; // hi John | |
| IIFEGreet(); // IIFEGreet is not a function | |
| // wrap in parentheses | |
| (function(name){ | |
| return 'hi ' + name; | |
| }('John')); // hi John | |
| (function(name){ | |
| return 'hi ' + name; | |
| })('John'); // hi John |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment