O'Reilly logo
  • Sri Harsha V thinks this is interesting:

When your JavaScript program execution enters a new function, all the variables declared anywhere in the function are moved (or elevated, or hoisted) to the top of the function. This is an important concept to keep in mind. Further, only the declaration is hoisted, meaning only the presence of the variable is moved to the top. Any assignments stay where they are.


Cover of Object-Oriented JavaScript - Second Edition


This is an important difference to bear in mind. It doesn't behave similar to C++ in this regard. All local variable declarations within a function are hoisted to the top of the function thus shadowing any known global variable supposedly visible at that part of the script.