web前端技术博客
您当前的位置:web前端 > JavaScript知识点

JavaScript 中的严格模式 use strict的使用

作者:只会切图的前端 发布时间:2021-01-26 09:34:03 浏览量:10

ECMAScript 5中提出了严格模式,use strict,限制了一些不规范的写法。
例如:
1、未声明的全局变量赋值会抛出ReferenceError ,而不会默认创建一个全局变量。
2、使用with、eval等语句时,抛出SyntaxError
3、全局变量不可以删除。

"use strict";
 var a=123;
 delete a;//VM175:3 Uncaught SyntaxError: Delete of an unqualified identifier in strict mode.
4、系统内置属性不可以删除。
5、已冻结对象属性、已密封对象属性不可删除。
6、函数参数不可以重名。
"use strict";
function a(v,v){};//Uncaught SyntaxError: Duplicate parameter name not allowed in this context

发表评论
验证码:

相关文章

    无相关信息
联系我
粤ICP备17092958号