当前位置:网站首页>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()
- 作用域链相关知识的总结:
作用域链始终遵循 从里往外一层一层寻找
自己的变量对象----->变量外部()局部环境的变量对象 ----->全局环境的变量对象。
边栏推荐
- [mindspore] [read graph data] cannot read mindrecord format graph data
- [Infographics Show] 248 Public Domain Name
- Sentinel simple current limiting and degradation demo problem record
- 分享 25 个有用的 JS 单行代码
- Dataframe first performs grouping operation and then combines output
- FormatDateTime说解[通俗易懂]
- Network RTK UAV test [easy to understand]
- Split very long line of words into separate lines of max length
- Skiing mobile H5 game source code download
- tiktok如何破零播放?
猜你喜欢

连接数据库警告 Establishing SSL connection without server‘s identity verification is not recommended.

9. < tag dynamic programming and subsequence, subarray> lt.718. Longest repeated subarray + lt.1143. Longest common subsequence

【神器】截图+贴图工具 Snipaste

JVM(二十三) -- JVM运行时参数

Binarysearch basic binary search

How to get started quickly in software testing

Add a subtitle of 3D effect to the container

PreScan快速入门到精通第十八讲之PreScan轨迹编辑的特殊功能

How to set tiktok mobile network environment? How can tiktok break the playback volume?

Rainbow plug-in extension: monitor MySQL based on MySQL exporter
随机推荐
导电滑环在机械设备方面的应用
高数_第3章重积分 学习体会与总结
如何保证定制滑环质量
Bash does not add single quotes to your string
当AI邂逅生命健康,华为云为他们搭建三座桥
wallys//IPQ5018/IPQ6010/PD-60 802.3AT Input Output 10/100/1000M
Advantages of network virtualization of various manufacturers
Three skills of interface request merging, and the performance is directly exploded!
How to ensure the quality of customized slip rings
sentinel简单限流和降级demo问题记录
Stochastic gradient descent method, Newton method, impulse method, adagrad, rmsprop and Adam optimization process and understanding
Sentinel simple current limiting and degradation demo problem record
Dataloader reports an error "default_collate: batch must contain tensors, numpy arrays, numbers, dicts" when pytorch trains the model
Rainbow plug-in extension: monitor MySQL based on MySQL exporter
Prescan quick start to master Lesson 19: prescan actuator configuration, track synchronization and non configuration of multiple tracks
Software designer afternoon real topic: 2009-2022
Detailed evaluation of current popular redis visual management tools
Difference Between Accuracy and Precision
【高等数学】【3】微分中值定理与导数的应用
[wp]ctfshow-web introductory information collection
