var foo = "Foo"; // globally scopedlet bar = "Bar"; // not allowed to be globally scopedconsole.log(window.foo); // Fooconsole.log(window.bar); // undefined + z. i8 I8 ^6 J6 }2 r( L7 d: J
Redeclaration在严格的模式下,var同时,它将允许您在同一范围内重新声明相同的变量let引发 SyntaxError。. ], D& F) D4 O
'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 5 r" a$ O' X( P" ? k8 S* r* I/ ?