首页 > 解决方案 > 全局变量的值不会改变

问题描述

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

如何通过函数更改全局变量的值?

标签: javascript

解决方案


推荐阅读