// 有些环境下它是不可以改变的 const PI = 3.141592653589793; PI = "modified!"; PI; // 3.141592653589793 //某些环境下,可能会把它当成var关键字对待 const PI = 3.141592653589793; PI = "modified!"; PI; // "modified!"
"use strict";
function f(x) { "use strict"; // ... }
function f(x) { "use strict"; var arguments = []; // error: redefinition of arguments // ... }
// file1.js "use strict"; function f() { // ... } // ...
//and another file that expects not to be in strict mode: // file2.js // no strict-mode directive function g() { var arguments = []; // ... } // ...
<script src="js/file1.js"></script> <script src="js/file2.js"></script>
// file1.js "use strict"; function f1() { // ... } // ... // file2.js // no strict-mode directive function g() { var arguments = []; // error: redefinition of arguments // ... } // ...
// file2.js // no strict-mode directive function g() { var arguments = []; // ... } // ... // file1.js "use strict"; function f() { // no longer strict // ... } // ...
(function() { "use strict"; function f() { // ... } function g() { // ... } // ... })();
原文:http://www.cnblogs.com/yugege/p/4972911.html