3

Just Curious to know whether there is any hack for it!

Example:

var a, b, c, d, e, f, g; //global Variables 

function add(para){
    para = 10+10;
};

add(a);

console.log(a); //Prints Undefined

I want to assign 10+10 to the global variable by passing the variable as parameter.

1 Answers1

2

You need to set the value of global variable a inside the function add(para) to get it's value outside the function in your console.log()

var a, b, c, d, e, f, g; //global Variables 

function add(para){
    para = 10+10;
    //set the value of a
    a = para;
};

add(a);

console.log(a);
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62