Global vs local variables


#1

Iam having problems understanding the global scope and local scope


#2

If your program has 1 or more funtions in it and if those functions use variables confined to the function only, that's a local variable to the function and not accessible from anywhere else in the program.
If you have variables declared in the program, generally, before you have any other code in the program, they will be global variables for the program.
This is a very superficial explanation.


#3

How would you go about the exercise?


#4

Are you asking for a code example ?


#5

Yes the code that invloves var my_number = 7


#6

You can google your question and get some far better examples


#7

Let's start by determining execution context of command line code. It will be window, the global window context.

var a, b, c;
console.log(this.a, this.b, this.c);
// undefined undefined undefined

Notice there is no ReferenceError? this in the current context is window, the context in which we declared the properties, a, b, and c.

Mull this over for a minute, and ping this topic for more discussion...