我知道为什么const在for循环中不起作用.我们需要创建一个新的范围并将值复制到其中.所以这不会飞.
for(const i = 0; i < 5; i++) console.log(i);
Run Code Online (Sandbox Code Playgroud)
虽然这样会.
for(let i = 0; i < 5; i++) console.log(i);
Run Code Online (Sandbox Code Playgroud)
但是,我注意到它们在循环通过像这样的对象的属性时工作.
for(let property in thingy) console.log(property);
for(const property in thingy) console.log(property);
Run Code Online (Sandbox Code Playgroud)
我不知道为什么.