THUDM / CodeGeeX2

CodeGeeX2: A More Powerful Multilingual Code Generation Model
https://codegeex.cn
Apache License 2.0
7.57k stars 533 forks source link

解释javascript 存在变量提升逻辑错误 #207

Open NewBieLD opened 4 months ago

NewBieLD commented 4 months ago
console.log(a) // ?
var a = 10

function a() {
  console.log(1111)
}
console.log(a) // ?

var a = 20

console.log(a) // ?

Code GEE 解释 值为 undefined // 此时变量a尚未被赋值,所以输出undefined 1111 // 调用函数a(),输出1111 20 // 将变量a的值更改为20,输出20

实际值为 // 1、提升 function a() { // console.log(1111) // } // 2、提升 var a // 3、执行代码 console.log(a) ---fuction a // 4、提升 a = 10 // 5、执行console.log(a)---- a = 10 // 6、执行a = 20 // 7、执行console.log(a)--- a = 20 image