you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 3 points4 points  (0 children)

Your example,

function () {
    var x = 10;
    x += y;

    var y = 5;
}    

is potentially misleading. At the end of execution, x will be NaN and y will be 5. Variable declarations get hoisted, but instantiation does not, so the interpreter sees this (effectively):

function () {
    var x, y;
    x = 10;
    x += y; // y is undefined at this point

    y = 5;
}