Simple JS code snippet result

The reason it returns undefined is because the a inside function foo() has a local scope right?
It does not have any co-relation with the a in the global scope which has a value of 1 , right?

function foo(){a=a+1;}
var a = 1;

No it returns undefined because you are not logging anything

how do I make it returns two then?

this does not work :

function foo(){console.log(a+1);}
var a = 1;

That logs 2. If you want to return 2, you can just use return a+1.

I see thanks! (20 character)

Mark this as solved now?