当前位置:网站首页>js 变量作用域和函数的学习笔记
js 变量作用域和函数的学习笔记
2022-07-06 09:17:00 【阿波次嘚】
变量的作用域:限定变量的可用范围,分为函数作用域和全局作用域。
函数作用域:
函数以外是全局作用域 – 变量只能在函数内部访问 (函数的形参 是局部变量–相当于内部声明了形参对应的变量)。
全局作用域:函数以内是函数作用域 – 变量可以在任意作用域下访问到。
~~在函数内部不加关键字(var)声明的就是全局变量,但是严格模式下这样声明不规范。
JS 是一门函数式编程语言,而函数是用于完成特定功能的代码块,当函数有返回值的时候可以作为一个变量的值,没有返回值时可以作为一个完成一个业务的工具。
~~当我们感觉用变量解决问题太过于繁琐和烧脑 则此时就要考虑是否抽个方法 来解决: “感觉没有什么问题却让你很难受” 的情况。
函数是一个Function类型的对象 它有两个 实用的内置属性:
(1) this
如图 this 在普通函数中 指向的是 window 对象,全局变量也相当于window对象的一个属性
所以在函数中通过this 也可以改变全局变量的值。
(2) arguments 表示 形参列表信息 – 参数 和 对应的值 (类数组对象)
和大家一起学习
边栏推荐
- 机器学习--线性回归(sklearn)
- Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries(XGBoost)
- ESP learning problem record
- Machine learning -- linear regression (sklearn)
- Distribute wxWidgets application
- Arduino gets the length of the array
- Encodermappreduce notes
- Oppo vooc fast charging circuit and protocol
- 数据分析之缺失值填充(重点讲解多重插值法Miceforest)
- Missing value filling in data analysis (focus on multiple interpolation method, miseforest)
猜你喜欢

Kconfig Kbuild

小天才电话手表 Z3工作原理

Unit test - unittest framework
![Several declarations about pointers [C language]](/img/9b/ace0abbd1956123a945a98680b1e86.png)
Several declarations about pointers [C language]

程序员老鸟都会搞错的问题 C语言基础 指针和数组
![[esp32 learning-1] construction of Arduino esp32 development environment](/img/31/dc16f776b7a95a08d177b1fd8856b8.png)
[esp32 learning-1] construction of Arduino esp32 development environment

【ESP32学习-2】esp32地址映射

Principle and implementation of MySQL master-slave replication

物联网系统框架学习

uCOS-III 的特点、任务状态、启动
随机推荐
机器学习--线性回归(sklearn)
GNN的第一个简单案例:Cora分类
Reading notes of difficult career creation
Imgcat usage experience
E-commerce data analysis -- salary prediction (linear regression)
XML file explanation: what is XML, XML configuration file, XML data file, XML file parsing tutorial
Basic use of pytest
map文件粗略分析
RT-Thread API参考手册
MySQL数据库面试题
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries
冒泡排序【C语言】
RT thread API reference manual
ESP8266通过arduino IED连接巴法云(TCP创客云)
Linux Yum install MySQL
ESP8266使用arduino连接阿里云物联网
arduino UNO R3的寄存器写法(1)-----引脚电平状态变化
Unit test - unittest framework
I2C bus timing explanation
Several declarations about pointers [C language]