Global vs Local Variables


#1

it is work but i don't know why ?
var my_number = 7; //this has global scope

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

timesTwo(7);

console.log("Outside the function my_number is: ")
console.log(my_number);


#2

you should have created a local variable inside your function:

var timesTwo = function(number) {
    var my_number = number * 2;

seems the exercise isn't airtight


#3

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