console.log(myName); var myName = “Gustavo”
var myName; console.log(myName); myName = “Gustavo”
“var myName;” is declared on top of the current scope. its assignment occurring afterwards at its original place. If you had run the first code you would get the console to print “undefined” rather than an error because of the variable declaration that was hoisted.
Because of this quirky behavior it is good practice to declare and assign your variables first.
var myName = “Gustavo”; console.log(myName);