0
Follow
0
View

A JS question, please answer - outside the definition of variables, function parameters, change variables within the function

dinghao851105 注册会员
2023-02-27 15:40

This answer quotes ChatGPT

In this code, the first console.log outputs "abc" because data was assigned "abc" before fun was called. Then, the fun function is called, taking data, which is "abc". Inside the fun function, concatenate data with the string "xyz" to produce a new string "abcxyz". However, this does not change the original data variable, because strings are immutable in JavaScript. So, when fun finishes, data is still "abc". So, when the second console.log is called, the output value is still "abc".

dadawfj 注册会员
2023-02-27 15:39

Because function arguments are passed based on value, the value of the data argument outside the function is not changed inside the function, so the output of the first console.log is still "abc".

About the Author

Question Info

Publish Time
2023-02-27 15:39
Update Time
2023-02-27 15:39

Related Question

我如何导入Pixi.js到TypeScript项目?

改变一个JSON数组会改变所有数组

升级js文件使用import

./src/index.js找不到文件:'App.js'不匹配磁盘上对应的名称:'.\src\components\ components '

MSScriptControl加载JS报错——缺少标识符

将data.frame按行传递给function,使用purrr/furrr代替apply

vue3:使用jsplumb绘制流程图

auto.js的找图找色的问题

获取JSON的每个值动态嵌套在clickhouse的每一行

如何检查用户是否已连接到discord.js中的语音通道?