console.log(foo); // ReferenceError: foo is not defined foo =1 ; console.log(foo); // output is undefined because var declaration bubbles into the top of the file .Hoisting var foo =1 ; console.log(foo); // ReferenceError: foo is not defined . let foo =1 ; foo =3 ; console.log(foo); var foo ; // output should be 3 because the var declaration of foo is now bubbled at the top so we can think that var foo exists even before foo=3 is declared // bubbles to the top foo(); // no errors function foo(){ }