I am currently studying the intricacies of JavaScript with the book "You don't know JavaScript". I have come to understand the fact that vars are hoisted and lets are not. However: if I bind a function to a var, for some reason it is not hoisted. Since I am a teacher I would very much like to really grasp the logic to this language, so can anyone explain to me the logical reason why the code below wouldn't work?
foo();
var foo = function() {
console.log("Foo!");
};
I would expect to be able to call the function, since not only would a regular function expression be allowed to be defined below to calling of that function, but also I am binding it to a var in this instance.
Help would be very much appreciated!