var foo = "Foo"; // globally scopedlet bar = "Bar"; // not allowed to be globally scopedconsole.log(window.foo); // Fooconsole.log(window.bar); // undefined! v- s" R4 L( X4 q0 p, X
Redeclaration在严格的模式下,var同时,它将允许您在同一范围内重新声明相同的变量let引发 SyntaxError。 6 h6 H. i- K/ y" j2 y4 a8 T
'use strict';var foo = "foo1";var foo = "foo2"; // No problem,'foo1' is replaced with 'foo2'.let bar = "bar1"; let bar = "bar2"; // SyntaxError: Identifier 'bar' has already been declared 1 C, Y" V. s$ a8 [