10. global vs local


#1

ar my_number = 7; //this has global scope

var timesTwo = function(number){
my_number = number * 2;
console.log("Inside the function my_number is: ");
console.log(my_number);
};
timesTwo(2);
console.log("Outside the function my_number is: ")
console.log(my_number);

Getting Error : Make sure you used the 'var' keyword inside the function!strong text


10. Global Vs. Local Variables - Question
#2

this line:

my_number = number * 2;

you should use the var keyword, to make the variable local


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.