全球变量的价值不会改变

时间:2020-05-06 03:05:10

标签: javascript

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

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

0 个答案:

没有答案
相关问题