当前位置:网站首页>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()
- 作用域链相关知识的总结:
作用域链始终遵循 从里往外一层一层寻找
自己的变量对象----->变量外部()局部环境的变量对象 ----->全局环境的变量对象。
边栏推荐
- 软件设计师下午真题:2009-2022
- Digital informatization (enumerate assumptions first, and then see whether the conditions are met) (1089 werewolf kill - simple version)
- PyTorch 模型 onnx 文件的导出和调用
- Creative drop-down multi choice JS plug-in download
- 9.< tag-动态规划和子序列, 子数组>lt.718. 最长重复子数组 + lt.1143. 最长公共子序列
- RepVGG网络中重参化网络结构解读【附代码】
- A high efficiency 0-delay 0-copy QT player scheme based on Hisilicon 3559
- C language learning diary 3 - realloc function
- Proxy implements MySQL read / write separation
- PreScan快速入门到精通第十九讲之PreScan执行器配置、轨迹同步及非配多个轨迹
猜你喜欢

4、Nacos 配置中心源码解析之 服务端启动

随机梯度下降法、牛顿法、冲量法、AdaGrad、RMSprop以及Adam优化过程和理解

Stochastic gradient descent method, Newton method, impulse method, adagrad, rmsprop and Adam optimization process and understanding
![[wp]ctfshow-web getting started - Explosion](/img/4b/6d8f4c044578382b9353d4d1c69c8f.png)
[wp]ctfshow-web getting started - Explosion

分享 25 个有用的 JS 单行代码

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

JVM (XXIII) -- JVM runtime parameters

Ml programming skills:
Detailed evaluation of current popular redis visual management tools

The query data returned by the print database is null or the default value. Does not match the value returned by the database
随机推荐
PMP adopts the latest exam outline, here is [agile project management]
10. < tag dynamic programming and subsequence, subarray> lt.53. maximum subarray and + lt.392. Judge subsequence DBC
High number_ Chapter 3 learning experience and summary of multiple integral
9.< tag-动态规划和子序列, 子数组>lt.718. 最长重复子数组 + lt.1143. 最长公共子序列
网络RTK无人机上机测试[通俗易懂]
Stochastic gradient descent method, Newton method, impulse method, adagrad, rmsprop and Adam optimization process and understanding
【高等数学】【1】函数、极限、连续
Proxy implements MySQL read / write separation
笔记——记录一个CannotFindDataSourceException: dynamic-datasource can not find primary datasource问题解决
RepVGG网络中重参化网络结构解读【附代码】
Advantages of network virtualization of various manufacturers
Introduction and construction of consul Registration Center
Socket error Event: 32 Error: 10053. Connection closing...Socket close
YOLOv7论文部分解读【含自己的理解】
JVM (XXIII) -- JVM runtime parameters
【高等数学】【3】微分中值定理与导数的应用
Univariate function integration_ Partial integral method
C # add multi line and multi column text watermark in word
[mindspore] [read graph data] cannot read mindrecord format graph data
[cloud native | learn kubernetes from scratch] VIII. Namespace resource quotas and labels
