当前位置:网站首页>js 变量作用域和函数的学习笔记
js 变量作用域和函数的学习笔记
2022-07-06 09:17:00 【阿波次嘚】
变量的作用域:限定变量的可用范围,分为函数作用域和全局作用域。
函数作用域:
函数以外是全局作用域 – 变量只能在函数内部访问 (函数的形参 是局部变量–相当于内部声明了形参对应的变量)。
全局作用域:函数以内是函数作用域 – 变量可以在任意作用域下访问到。
~~在函数内部不加关键字(var)声明的就是全局变量,但是严格模式下这样声明不规范。
JS 是一门函数式编程语言,而函数是用于完成特定功能的代码块,当函数有返回值的时候可以作为一个变量的值,没有返回值时可以作为一个完成一个业务的工具。
~~当我们感觉用变量解决问题太过于繁琐和烧脑 则此时就要考虑是否抽个方法 来解决: “感觉没有什么问题却让你很难受” 的情况。
函数是一个Function类型的对象 它有两个 实用的内置属性:
(1) this
如图 this 在普通函数中 指向的是 window 对象,全局变量也相当于window对象的一个属性
所以在函数中通过this 也可以改变全局变量的值。
(2) arguments 表示 形参列表信息 – 参数 和 对应的值 (类数组对象)
和大家一起学习
边栏推荐
猜你喜欢

Gallery之图片浏览、组件学习

Characteristics, task status and startup of UCOS III

Working principle of genius telephone watch Z3

uCOS-III 的特点、任务状态、启动

Arm pc=pc+8 is the most understandable explanation

Correspondence between STM32 model and contex M

Kaggle competition two Sigma connect: rental listing inquiries (xgboost)

OPPO VOOC快充电路和协议

R & D thinking 01 ----- classic of embedded intelligent product development process

Analysis of charging architecture of glory magic 3pro
随机推荐
Use of lists
高通&MTK&麒麟 手机平台USB3.0方案对比
Machine learning -- linear regression (sklearn)
mysql实现读写分离
Basic knowledge of lithium battery
Programmers can make mistakes. Basic pointers and arrays of C language
Comparison of solutions of Qualcomm & MTK & Kirin mobile platform USB3.0
Principle and implementation of MySQL master-slave replication
Esp8266 uses Arduino to connect Alibaba cloud Internet of things
B tree and b+ tree of MySQL index implementation
C language callback function [C language]
JS变量类型以及常用类型转换
Using LinkedHashMap to realize the caching of an LRU algorithm
几个关于指针的声明【C语言】
RT thread API reference manual
Reading notes of difficult career creation
imgcat使用心得
There are three iPhone se 2022 models in the Eurasian Economic Commission database
机器学习--线性回归(sklearn)
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries(XGBoost)