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
如何通过函数更改全局变量的值?
解决方案
推荐阅读
- javascript - 在 JSON 中将字符串转换为数字
- laravel-7 - 不支持的驱动程序 []
- redux - 基于 Web 套接字响应调度操作
- python - Python matplotlib,如何将条形图分组
- angular - 拒绝应用样式,因为它的 MIME 类型('text/html')不是受支持的样式表 MIME 类型,并且在 Angular 中启用了严格的 MIME 检查
- javascript - 如何停止 CSS 旋转动画
- azure-active-directory - AzurePRT 与混合 Az AD 设备加入 - OneDrive 仍然保存信用?
- python - 计算数据框中的子记录数
- flutter - 颤振:如何从非 Firebase 源获取推送通知有效负载
- drools - 如何找到需要很长时间才能完成的规则