Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of function and variable hoisting.
/* Function Hoisting Example */
//This will run despite being declared below
console.log(myFuction());
//This also applies to variables although x = undefined here
console.log("x value:", x);
function myFuction() {
console.log("I was called");
}
console.log("I was created");
//Will assign x properly here
var x = 5;
console.log("x value:", x);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment