I'm learning Javascript at the minute and have a question about hoisting/scoping - perhaps I'm missing something.
If I define a global variable, I cant reference that variable's value inside a function because its out of scope?
var x = "hello";
function temp(){
console.log(x);
}
turns out to be
var x = "hello";
function temp(){
var x;
console.log(x);
}
which both outputs undefined. What are the points of global variables or how do you use them inside a function? - As I said what am i missing here! :)
Also hoisting works on functions? But NOT on anonymous functions? Correct?
Any help is appreciated!
Thanks!