10. Global vs Local Variables. What is "var" actually doing?


#1

Is the "var" keyword defining a variable's value or its scope?

Originally I thought you would use "var" to assign a value to a variable:

var my_number = 7;

But in the code below the variable my_number is being assigned a value without using "var".

my_number = number * 2;

Does this mean that technically you don't need to use "var" to assign values to a variable unless scope is a concern? (Presumably scope would usually be a concern.) How about declaring a variable in the first place? "Var" is optional or required?


#2

Good evening,

I am also glad to see your enthusiasm in seeking to understand more than what the exercises are giving you. I attempted to answer your question myself though I feel this does the best service to giving you a full explanation for what you asked.