当前位置:网站首页>day25 js中的预解析、递归函数、事件 2021.09.16
day25 js中的预解析、递归函数、事件 2021.09.16
2022-06-28 11:20:00 【即将成为大佬的小梦】
预解析:(变量提升)
代码在执行之前先进行解析,将变量和函数的声名放在当前作用域的最前面。
总结:
1.用var关键字声名的变量,将变量的声名提升到当前作用域的最前面,赋值不提升
2.自定义的函数整体提升到当前作用域的最前面
3.函数同名,后面的会覆盖前面的
4.变量和函数同名,函数优先提升
面试题:
//1.
var num = 10;
fn1();
function fn1() {
console.log(num);
var num = 20;
}
//2.
var a = 18;
fn2();
function fn2() {
var b = 9;
console.log(a);
console.log(b);
}
//3.
fn3();
console.log(c);
console.log(b);
console.log(a);
function fn3() {
var a = b = c = 9;
console.log(a);
console.log(b);
console.log(c);
}
//4. 思考题
var a = 4;
console.log(a);
a = 6;
console.log(a);
function a() {
console.log('哈');
}
a();
a = 10;
console.log(a);
函数的嵌套:(函数中调用函数)
作用域:
1.函数外边的变量叫做全局变量,可以在函数外面和函数里面使用。
2.函数内部的变量叫做局部变量,只能在函数内部使用。
变量访问和赋值:会在当前作用域查找,如果没有会往上级查找 直至找到全局
访问:全局中也没有的话 就会报错 也会显示undefiend
赋值:全局中没有的话 就会自己定义一个变量 并且赋值
递归函数:(就是在函数中调用自己)造成内存消耗 性能比较差
// 求10的阶和,即:10+9+8+...+1
function facSum(num){
if(num == 1){
return 1;
}
return num + facSum(num-1);
}
var res = facSum(10);
console.log(res); // 55
事件:(用户在网页上的动作,例如:鼠标点击、鼠标移动、键盘按下)
-1)通过绑定结构 触发函数执行调用 绑定的名称.事件名称 = function(){}
- 2)通过绑定结构 触发函数执行调用 绑定的名称.事件名称 = 函数名称 后面执行的小括号不能有
鼠标类事件:
- onclick 单击事件
- ondblclick 双击
- onmousemove 鼠标移入
- onmouseout 鼠标移出 鼠标移入进来灭有变化 当移出一次会变化一次
- onmousedown 鼠标按下
- onmouseup 鼠标抬起
- oncontextmenu 右击
键盘类事件: 绑定对象是window
- onkeydown 键盘按下
- onkeyup 键盘抬起
- onkeypress 键盘敲击 绑定键位
表单类事件:验证
- onfocus 聚焦
- onblur 失去焦点
- onchange 改变
边栏推荐
- Day39 prototype chain and page Fireworks Effect 2021.10.13
- 阿里三面:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
- js中的class类模式及语法 2021.11.10
- [QT] connect syntax reference implementation
- Scientific research - web of science retrieval skills
- Graduation season, some suggestions for you who are new to the society
- setInterval、setTimeout和requestAnimationFrame
- 使用ssm项目对Mysql8进行访问的时候,出现连接失败和一些错误的解决办法
- windows 10下载安装mysql5.7
- MySQL installation configuration and solving the problem of forgetting root password when reinstalling MySQL
猜你喜欢

Dataease installation upgrade

行业分析| 快对讲,楼宇对讲

一套十万级TPS的IM综合消息系统的架构实践与思考

人人都可以参与开源!龙蜥社区最不容错过的开发者活动来了

js中的class类模式及语法 2021.11.10

利用soapUI获取freemarker的ftl文件模板

JS foundation 3

day39 原型链及页面烟花效果 2021.10.13

Metersphere implements UI automation elements that are not clickable (partially occluded)

day37 js笔记 运动函数 2021.10.11
随机推荐
关于Pytorch中双向LSTM的输出表示问题
一套十万级TPS的IM综合消息系统的架构实践与思考
智联招聘基于 Nebula Graph 的推荐实践分享
day39 原型链及页面烟花效果 2021.10.13
Graduation season, some suggestions for you who are new to the society
[practice] 1364- implement a perfect waterfall flow component on the mobile terminal (with source code)
Redis6 1: what problems can be solved by the introduction of NoSQL and redis?
It is safer for individuals to choose which securities company to open an account for buying floor funds
近况
QML控件类型:TabBar
Mysql使用max函数查询不到最大值
Which broker is safer and more convenient to open an account for Oriental Fortune mobile stock?
day39 原型鏈及頁面烟花效果 2021.10.13
Download and install mysql5.7 for windows 10
This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors
毕业了
ProCAST有限元铸造工艺模拟软件
Apache2配置对目录拒绝访问,但是可以访问里面文件的设置
Docker modifies the user name and password of MySQL
What is the function of ICMP Protocol and the principle of Ping of death attack?