当前位置:网站首页>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()
- 作用域链相关知识的总结:
作用域链始终遵循 从里往外一层一层寻找
自己的变量对象----->变量外部()局部环境的变量对象 ----->全局环境的变量对象。
边栏推荐
- C # add multi line and multi column text watermark in word
- Introduction and construction of consul Registration Center
- 使用cookie登录百度网盘(网站使用cookie)
- PMP采用最新考纲,这里有【敏捷项目管理】
- Legal mix of collations for operation 'Union' (bug record)
- Deeplobv1 and V2
- Proxy实现mysql读写分离
- 【云原生 | 从零开始学Kubernetes】八、命名空间资源配额以及标签
- Digital informatization (enumerate assumptions first, and then see whether the conditions are met) (1089 werewolf kill - simple version)
- 什么是聚类分析?聚类分析方法的类别[通俗易懂]
猜你喜欢

Socket error Event: 32 Error: 10053. Connection closing...Socket close

当AI邂逅生命健康,华为云为他们搭建三座桥

YOLOv7论文部分解读【含自己的理解】

The query data returned by the print database is null or the default value. Does not match the value returned by the database

Creative drop-down multi choice JS plug-in download

sentinel简单限流和降级demo问题记录

Stochastic gradient descent method, Newton method, impulse method, adagrad, rmsprop and Adam optimization process and understanding

Six axis sensor use learning record

UNET and mask RCNN

03 isomorphism of tree 1
随机推荐
wallys//wifi6 wifi5 router IPQ6018 IPQ4019 IPQ4029 802.11ax 802.11ac
UNET and mask RCNN
一元函数积分学_分部积分法
Stochastic gradient descent method, Newton method, impulse method, adagrad, rmsprop and Adam optimization process and understanding
Configure and install cocos2dx development environment under Tongxin UOS
Authorized wireless communication standard
tga文件格式(波形声音文件格式)
[Infographics Show] 248 Public Domain Name
Pytorch's transforms (numpy data type is converted to tensor, normalized and resized)
Share 25 useful JS single line codes
【高等数学】【6】多元函数微分学
Deeplobv1 and V2
Error when creating dataset with mindscore
CarSim仿真快速入门(十六)—CarSim传感器仿真之ADAS Sensor Objects (2)
Timing analysis and constraints based on xlinx (1) -- what is timing analysis? What are temporal constraints? What is temporal convergence?
Can you tell me whether mindspore supports torchvision Model directly uses the pre trained network, such as vgg16
PyTorch 模型 onnx 文件的导出和调用
10. < tag dynamic programming and subsequence, subarray> lt.53. maximum subarray and + lt.392. Judge subsequence DBC
Web crawler principle analysis "suggestions collection"
What is cluster analysis? Categories of cluster analysis methods [easy to understand]
