I want to make a function more reusable by being able to give variable name to it and modify the value of that variable within the function from that variable.
Kind of like this:
var number1;
function one(){
number1 = 10;
two(number1);
}
function two(varname){
varname = varname * 10;
}
How can I do that?
If you send the variable through as a string, you can reference it using this
var number1;
function one(){
number1 = 10;
two("number1");
}
function two(varname){
this[varname] = this[varname] * 10;
}
one()
console.log(number1)