当前位置:网站首页>JS中对作用域链的理解(查找变量)
JS中对作用域链的理解(查找变量)
2022-08-02 00:14:00 【weixin_46051260】
作用域:变量和函数生效的区域
1)全局作用域:任何不在函数中或者大括号中声明的变量,都是在全局作用域下
全局作用域下的声明的变量可以在程序中任何位置访问
2)函数作用域:函数作用域中定义的变量,只能在函数内部访问,不能在函数外部访问
3)块级作用域:let和const定义的变量在大括号外面不可以被访问
作用域链
js使用一个变量,首先js引擎会在当前作用域下查找
如果没有找到,去上层作用域寻找,以此类推,知道找到变量或者到达全局作用域,如果没有找到,直接报错或者隐式声明
边栏推荐
- Identify memory functions memset, memcmp, memmove, and memcpy
- Don't concatenate strings with jOOQ
- nodeJs--mime模块
- CRS management and maintenance
- 07-SDRAM: FIFO control module
- 【CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)(A~D)】
- 具有通信时延的多自主体系统时变参考输入的平均一致性跟踪
- IP Core: FIFO
- Difference between JSP out.print() and out.write() methods
- How to design a circular queue?Come and learn~
猜你喜欢

思维导图,UML在线画图工具

PHP从txt文件中读取数据的方法

22. The support vector machine (SVM), gaussian kernel function

已知中序遍历数组和先序遍历数组,返回后序遗历数组

Play NFT summer: this collection of tools is worth collecting

Unknown CMake command "add_action_files"

什么是低代码(Low-Code)?低代码适用于哪些场景?

These 4 computer notepad software, you have to try
![[Headline] Written test questions - minimum stack](/img/67/08f2be8afc780e3848371a1b5e04db.png)
[Headline] Written test questions - minimum stack

路由策略
随机推荐
信息物理系统状态估计与传感器攻击检测
工业信息物理系统攻击检测增强模型
众筹DAO“枯萎”的缩影:曾拍下《沙丘》未出版手稿的Spice DAO解散
【21天学习挑战赛】顺序查找和二分查找的小总结
Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation
Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)
基于编码策略的电网假数据注入攻击检测
ICML 2022 || 局部增强图神经网络GNN,在 GCN 和 GAT基础上 平均提高了 3.4% 和 1.6%
Web开发
含外部储能的电力系统暂态稳定分布式控制
Transient Stability Distributed Control of Power System with External Energy Storage
146. LRU 缓存
nodeJs--各种路径
A simple file transfer tools
632. Minimum interval
When Netflix's NFTs Forget Web2 Business Security
IP Core: FIFO
Redis-消息发布订阅
Industrial control network intrusion detection based on automatic optimization of hyperparameters
BGP first experiment