Created
September 1, 2020 06:21
-
-
Save emre-edu-tech/ea442f06e75abed1203d564001ed37a4 to your computer and use it in GitHub Desktop.
This example shows the importance of Javascript 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
let result = 1; | |
// here this declaration must come first before using it | |
// it is a function variable declaration so it should be declared before its usage | |
const addNumber = function (numToAdd) { | |
result = result + numToAdd; | |
return result; | |
} | |
console.log(addNumber(3)); // outputs 4 | |
console.log(result); // outputs 4 | |
// function addNumber(numToAdd) { | |
// result = result + numToAdd; | |
// return result; | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment