Variable and Function Hoisting

One of the quirkiest things about JavaScript is this thing known as hoisting. We'll get to what it means in a bit, but let's set the stage for it by looking at some examples and figuring out what the right behavior should be. For our first example, take a look at the following code:


This is a companion discussion topic for the original entry at http://www.kirupa.com/html5/hoisting.htm
1 Like

No mention of let and const?

The hoisting mechanics you describe are notional — “as if” — behavior. Also, hoisting happens because it’s in the language spec, not because it’s an optimization. It’s mostly a vestigial remnant of early versions of JS.

Tough crowd…

2 Likes

:sweat_smile: Kirupa’s biggest fans are also his harshest critics.

Haha! Thanks for pointing these out. I will address them shortly :stuck_out_tongue:

Edit: Addressed!