1

let name;
let hobbie;
let occupation;

function setValue(aVariable, aValue){
    aVariable = aValue;
}

setValue(name, "John");
setValue(hobbie, "Travelling");
setValue(occupation, "Programmer");

console.log(name); // returns -> undefined
console.log(hobbie); // returns -> undefined
console.log(occupation); // returns -> undefined

How do I change the value of the global variables by a function?

Pramod
  • 11
  • 2
  • Reassigning a variable name won't have any side-effects (except in extremely rare cases), you'll have to actually reference the variable if you want to reassign it – CertainPerformance May 06 '20 at 03:06

0 Answers0