Last active
September 15, 2020 17:03
-
-
Save kallefrombosnia/f850d0e7150919617ee382efa73fe9a0 to your computer and use it in GitHub Desktop.
JS function hoisting
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
// Demo example on https://repl.it/repls/SpottedUnwieldyMenu | |
// This will work | |
normalFunction(); | |
function normalFunction(){ | |
console.log('common dummy text'); | |
} | |
// This will not work | |
arrowFunction(); | |
const arrowFunction = () => { | |
console.log('another dummy text from arrowFunction'); | |
} | |
/* Output: | |
common dummy text | |
ReferenceError: arrowFunction is not defined | |
at /home/runner/SpottedUnwieldyMenu/index.js:9:1 | |
at Script.runInContext (vm.js:133:20) | |
at Object.<anonymous> (/run_dir/interp.js:156:20) | |
at Module._compile (internal/modules/cjs/loader.js:778:30) | |
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) | |
at Module.load (internal/modules/cjs/loader.js:653:32) | |
at tryModuleLoad (internal/modules/cjs/loader.js:593:12) | |
at Function.Module._load (internal/modules/cjs/loader.js:585:3) | |
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment