Simple JS code snippet result

Simple JS code snippet result
0

#1

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;
foo();

#2

No it returns undefined because you are not logging anything


#3

how do I make it returns two then?

this does not work :

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

#4

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


#5

I see thanks! (20 character)


#6

Mark this as solved now?