当前位置:网站首页>JS作用域与作用域链
JS作用域与作用域链
2022-07-25 20:08:00 【InfoQ】
作用域
局部作用域
一般只在固定的代码片段内可以访问得到
function add(){
var name = "测试"
console.log(name)
}
add()
// console.log(name) name is not defined
全局作用域
var name = "外部"
function add(){
var name = "测试"
console.log(name)
}
add()
console.log(name)
作用域链
var name = "Out"
function out(){
var inOut = "In";
function inTao(){
console.log("inTao---------------"+inOut)
//undefined , 为什么会是undefinded呢,
//因为它先会从自身作用域中查找是否有inOut,如果有,并且inOut 提前在前面申明,那么就会正确显示值;否则显示undefinded,因为它只知道当前环境下有一个inOut
var ss = name;
var inOut = ss;
console.log("赋值后的ss-----------"+ss) //Out
console.log("inTao修改后的inOut-----------"+inOut) // Out
}
inTao()
}
console.log("外部的name---------------"+name) // Out
out()
- 作用域链相关知识的总结:
作用域链始终遵循 从里往外一层一层寻找
自己的变量对象----->变量外部()局部环境的变量对象 ----->全局环境的变量对象。
边栏推荐
- 项目中new Promise和async、await中的使用,以及promise.all在项目中的实际应用
- [wp]ctfshow-web getting started - Explosion
- Redis source code -ziplist
- DIY personal server (DIY storage server)
- Can you tell me whether mindspore supports torchvision Model directly uses the pre trained network, such as vgg16
- CarSim simulation quick start (XIV) - CarSim Simulink joint simulation
- Legal mix of collations for operation 'Union' (bug record)
- RepVGG网络中重参化网络结构解读【附代码】
- Network RTK UAV test [easy to understand]
- Link list of sword finger offer question bank summary (III) (C language version)
猜你喜欢

The JS paging plug-in supports tables, lists, text, and images

RepVGG网络中重参化网络结构解读【附代码】

4. Server startup of source code analysis of Nacos configuration center

4everland storage node portal network design

【高等数学】【6】多元函数微分学

test
![Summarize the level of intelligent manufacturing discussion [macro understanding]](/img/84/3addabdf857c562535a4085782d3e8.png)
Summarize the level of intelligent manufacturing discussion [macro understanding]

Introduction and construction of consul Registration Center

Google pixel 6A off screen fingerprint scanner has major security vulnerabilities

【高等数学】【8】微分方程
随机推荐
Prescan quick start to master Lesson 19: prescan actuator configuration, track synchronization and non configuration of multiple tracks
什么是聚类分析?聚类分析方法的类别[通俗易懂]
飞行器pid控制(旋翼飞控)
网络爬虫原理解析「建议收藏」
接口请求合并的3种技巧,性能直接爆表!
Rainbond插件扩展:基于Mysql-Exporter监控Mysql
推荐系统专题 | MiNet:跨域CTR预测
Socket error Event: 32 Error: 10053. Connection closing...Socket close
Recommendations on how to install plug-ins and baby plug-ins in idea
How to set tiktok mobile network environment? How can tiktok break the playback volume?
Export and call of onnx file of pytorch model
tiktok手机网络环境怎么设置?tiktok怎么破播放量?
What is the method to load the torch pre trained model for the mindspore model finetune?
Siemens PLM Teamcenter download, installation and use tutorial
PreScan快速入门到精通第十九讲之PreScan执行器配置、轨迹同步及非配多个轨迹
QQ是32位还是64位软件(在哪看电脑是32位还是64位)
Skiing mobile H5 game source code download
qml 结合 QSqlTableModel 动态加载数据 MVC「建议收藏」
谷歌Pixel 6a屏下指纹扫描仪存在重大安全漏洞
RF, gbdt, xgboost feature selection methods "recommended collection"
