发生这种情况是因为 JavaScript 与提升的工作方式有关。函数function VARIABLENAME() {}会在变量的“存在”调用下调出,并且变量更改值保留在其位置,但由于函数向上移动而相对向下移动。第一组(() => { var x function x() {} console.log(x)})()// This gets converted to:(() => { var x // This variable exists x = function x() {} // Ya know that variable called x? well its a function console.log(x)})()第二组(() => { var x = 1 function x() {} console.log(x)})()// This gets converted to:(() => { var x // the variable x exists x = function x() {} // Functions are moved to the top, under variable declarations x = 1 // x is now the value 1 console.log(x)})()