JavaScript的“严格”和“非严格”模式有什么区别?

“ use strict”是一条指令,它是一个文字表达。它在JavaScript 1.8.5中引入。顾名思义,“使用严格”表示代码将在严格模式下执行。在非严格条件下,代码将不会执行,也不会在严格模式下执行。

让我们声明严格模式。要声明,请在开头添加关键字“ use strict”。对于全局作用域,请在脚本开头声明它。

<!DOCTYPE html>

<html>

   <body>

      <p>An error would come, since you have used a variable, but forgot to declare it</p>

      <p>Press F8 to see the error.</p>

      <script>

         "use strict";

         a = 1;

      </script>

   </body>

</html>

以上是 JavaScript的“严格”和“非严格”模式有什么区别? 的全部内容, 来源链接: utcz.com/z/355663.html

回到顶部