Yeah I believe I understand that one, The first console.log is undefined because the variable is not global but the second console.log says "local" because your logging it inside of the function where the variable exists right?
Originally Posted by tech_soul8
Hm...close but not exactly like that.
All variables inside of a function are visible throughout the body of the function. This is known as hoisting! All variables (but not associated assignments) are "hoisted" to the top of the function. That means that if you try to reference your variable prior to the point in a code where the actual assignment happens you'll get a value of undefined because that's the value of uninitialized variables.
The same thing applies in a case of a function expressions and a function declaration statements but you'll get to that in your future lectures I guess.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)