当前位置:网站首页>js严格模式
js严格模式
2022-08-11 05:17:00 【前端小马】
介绍
JavaScript 除了提供正常模式外,还提供了严格模式(strict mode)。ES5 的严格模式是采用具有限制性 JavaScript变体的一种方式,即在严格的条件下运行 JS 代码。
严格模式在 IE10 以上版本的浏览器中才会被支持,旧版本浏览器中会被忽略。
严格模式消除了 Javascript 语法的一些不合理、不严谨之处,减少了一些怪异行为
使用:
使用 "use strict" 指令
<script>
"use strict"; //全局开启
</script>
function fn(){
"use strict";//单独为某个函数开启
......
} 严格模式的特点:
'use strict'
num = 10
console.log(num)//严格模式后使用未声明的变量会报错,必须先声明在使用
---------------------------------------------------------------------
'use strict'
var num2 = 1;
delete num2;//报错,严格模式不允许删除声明好得变量
---------------------------------------------------------------------
'use strict'
function fn() {
console.log(this); // 严格模式下全局作用域中函数中的 this 是 undefined
}
fn();
---------------------------------------------------------------------
"use strict"
function testRepeatName(a, a, b){
console.log(a)
console.log(b)
}
testRepeatName(10, 20, 30)//报错,严格模式下函数参数不能重名,非严格模式输出20,30边栏推荐
- Flask framework to study: the debug and configuration items
- [C language from elementary to advanced] Part 1 Initial C language (1)
- Markdown 常用到的一些编写技巧
- 最全总结Redis数据类型使用场景
- Koa的使用,搭建本地服务器(必会技能)
- Chapter 5 Loops and Relational Expressions
- 做款好喝的茶饮~
- 【win10+cuda7.5+cudnn6.0安装caffe②】安装Visual Studio 2013和caffe
- 【记录】没用知识点 - 智力题
- Install different versions of MinGW (g++/gcc) and the configuration of the corresponding clion editor under Win
猜你喜欢
随机推荐
C - file operations fseek () function, ftell, rewind, rounding
09-ES6语法:变量、箭头函数、类语法、静态属性及非静态属性
吃瓜教程task01 第1章 绪论
第6章 分支语句和逻辑运算符
c pointer learning (2)
【CSDN21天学习挑战赛】第一天,配置环境外加实现mnist手写数字识别
2021研究生数学建模D题,BP神经网络和卷积神经网络解题代码(基于pytorch)
自制病毒——整蛊
【win10+cuda7.5+cudnn6.0安装caffe③】编译及测试caffe
C语言——程序的编译与执行、宏定义详解
Randomly generate uuid using rand function
家·谱——人脸识别家谱系统
使用Go语言开发的低代码应用引擎
【记录】innerHeight?clientHeight?offsetHeight?scrollTop?screenTop?.....一堆高度傻傻分不清
uniapp中设置tabBar及其窗口标题
【翻译】博客游戏项目Q1K3 – 制作
LeetCode43.字符串相乘 (大数相乘可用此方法)
07-nodemon安装和使用
C语言之EOF、feof函数、ferror函数
Some Error in Visual Studio solution









