-
-
Save fluency03/7ba15eef2fdfd237d2d029bf5c4df0a7 to your computer and use it in GitHub Desktop.
JS hoisting by example
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
| // A (works) | |
| function sayHi() { | |
| console.log('hi!') | |
| } | |
| sayHi() |
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
| // B (works) | |
| sayHi() | |
| function sayHi() { | |
| console.log('hi!') | |
| } |
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
| // C (works) | |
| var sayHi = function() { | |
| console.log('hi!') | |
| } | |
| sayHi() |
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
| // D (does not work) | |
| sayHi() | |
| var sayHi = function() { | |
| console.log('hi!') | |
| } |
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
| // E (does not work) | |
| (function sayHi() { | |
| console.log('hi!') | |
| }) | |
| sayHi() |
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
| // F (does not work) | |
| sayHi() | |
| (function sayHi() { | |
| console.log('hi!') | |
| }) |
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
| // G (works) | |
| (function sayHi() { | |
| console.log('hi!') | |
| })() |
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
| // H (works) | |
| (function() { | |
| console.log('hi!') | |
| })() |
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
| // I (works) | |
| var sayHi = (function() { | |
| console.log('hi!') | |
| })() |
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
| // J (works) | |
| var sayHi = (function() { | |
| console.log('hi!') | |
| }) | |
| sayHi() |
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
| // K (does not work) | |
| sayHi() | |
| var sayHi = (function() { | |
| console.log('hi!') | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment