当前位置:网站首页>js 变量作用域和函数的学习笔记
js 变量作用域和函数的学习笔记
2022-07-06 09:17:00 【阿波次嘚】
变量的作用域:限定变量的可用范围,分为函数作用域和全局作用域。
函数作用域:
函数以外是全局作用域 – 变量只能在函数内部访问 (函数的形参 是局部变量–相当于内部声明了形参对应的变量)。
全局作用域:函数以内是函数作用域 – 变量可以在任意作用域下访问到。
~~在函数内部不加关键字(var)声明的就是全局变量,但是严格模式下这样声明不规范。
JS 是一门函数式编程语言,而函数是用于完成特定功能的代码块,当函数有返回值的时候可以作为一个变量的值,没有返回值时可以作为一个完成一个业务的工具。
~~当我们感觉用变量解决问题太过于繁琐和烧脑 则此时就要考虑是否抽个方法 来解决: “感觉没有什么问题却让你很难受” 的情况。
函数是一个Function类型的对象 它有两个 实用的内置属性:
(1) this
如图 this 在普通函数中 指向的是 window 对象,全局变量也相当于window对象的一个属性
所以在函数中通过this 也可以改变全局变量的值。
(2) arguments 表示 形参列表信息 – 参数 和 对应的值 (类数组对象)
和大家一起学习
边栏推荐
猜你喜欢
Basic use of pytest
FTP file upload file implementation, regularly scan folders to upload files in the specified format to the server, C language to realize FTP file upload details and code case implementation
Linux Yum install MySQL
Understanding of AMBA, AHB, APB and Axi
open-mmlab labelImg mmdetection
Mall project -- day09 -- order module
ES6语法总结--上篇(基础篇)
Kaggle competition two Sigma connect: rental listing inquiries
Characteristics, task status and startup of UCOS III
Gallery's image browsing and component learning
随机推荐
Characteristics, task status and startup of UCOS III
电商数据分析--用户行为分析
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries(XGBoost)
MySQL数据库面试题
[esp32 learning-2] esp32 address mapping
Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
ESP8266使用arduino连接阿里云物联网
RT-Thread 线程的时间片轮询调度
Missing value filling in data analysis (focus on multiple interpolation method, miseforest)
Encodermappreduce notes
E-commerce data analysis -- User Behavior Analysis
sklearn之feature_extraction.text.CountVectorizer / TfidVectorizer
物联网系统框架学习
imgcat使用心得
C语言,log打印文件名、函数名、行号、日期时间
Arduino uno R3 register writing method (1) -- pin level state change
Unit test - unittest framework
arduino JSON数据信息解析
高通&MTK&麒麟 手機平臺USB3.0方案對比
E-commerce data analysis -- salary prediction (linear regression)