Skip to content

Instantly share code, notes, and snippets.

@emre-edu-tech
Created September 1, 2020 06:21
Show Gist options
  • Save emre-edu-tech/ea442f06e75abed1203d564001ed37a4 to your computer and use it in GitHub Desktop.
Save emre-edu-tech/ea442f06e75abed1203d564001ed37a4 to your computer and use it in GitHub Desktop.
This example shows the importance of Javascript hoisting.
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