如何使用“严格模式”保护我的JavaScript?
“usestrict”是一条指令,它是一个文字表达。它在JavaScript1.8.5中引入。顾名思义,“使用严格”表示代码将在严格模式下执行。
让我们声明严格模式。要声明,请在开头添加关键字“usestrict”。对于全局作用域,请在脚本开头声明它。
示例
<!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>输出结果
An error would come, since you have used a variable, but forgot to declare it Press F8 to see the error.
热门推荐
10 医院探望朋友祝福语简短
11 毕业祝福语简短女朋友
12 春节虎年爸妈祝福语简短
13 儿童毕业祝福语 简短6
14 开工仪式横幅祝福语简短
15 孩子日常祝福语大全简短
16 清晨寄语诗句祝福语简短
17 结婚送亲认亲祝福语简短
18 虎年喝酒拜年祝福语简短