当前位置:网站首页>学习笔记(7)Funtion
学习笔记(7)Funtion
2022-08-02 07:22:00 【酒鼎】
1,函数
1.1,函数声明
关键词funtion
:声明一个函数,格式:funtion 函数名(参数列表){函数体}
function people(name, age, sex) {
}
在js函数中声明的变量,会成为函数的局部变量。局部变量只能在函数内访问。
局部变量在函数开始时创建,在函数完成时被删除。
1.2,函数调用
函数调用格式为:函数名(实参列表)。
实参:函数调用时,传递的参数。
function people(name, age, sex) {
console.log(name)
}
people("小明", 30, true); //小明
调用函数时,函数的函数体代码会被执行,函数中的参数值就是本次调用所传递进去的。
函数调用本身也是一个表达式,表达式的值就是函数的返回值。
1.3,函数返回
当js执行到达 return 语句,函数将停止执行。
如果函数被某条语句调用,js将在调用语句之后“返回”执行代码。
function people(name, age, sex) {
console.log(name)
console.log(age)
return 123;
console.log(sex)
}
let men = people("小明", 30, true);
console.log(men)
/* 控制台输出 * 小明 * 30 * 123 */
作用域:每一个参数都有一个作用范围,超过范围就失效,这个范围就叫作用域。
边栏推荐
- 通过建立新的SaaS业务来推动增长的六种方法
- A full review of mainstream timed task solutions
- Chain Of Responsibility
- (2022 Nioke Duo School 5) C-Bit Transmission (Thinking)
- 常用的云安全防护措施盘点
- RIP综合实验
- MySQL - locking mechanism
- HCIP第一天
- MySQL报错1055解决办法:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
- Understand the Chisel language. 30. Chisel advanced communication state machine (2) - FSMD: Take Popcount as an example
猜你喜欢
MySQL - locking mechanism
HCIP 第八天
Fatal error compiling: 无效的目标发行版: 11
MySQL-慢查询日志
Understand the Chisel language. 30. Chisel advanced communication state machine (2) - FSMD: Take Popcount as an example
spark架构
Splunk Filed extraction field interception
MySQL-Execution Process + Cache + Storage Engine
HCIP第一天
2022-08-01 第四小组 修身课 学习笔记(every day)
随机推荐
regular expression
About the SQL concat () function problem, how to splice
责任链模式(Chain Of Responsibility)
ROS file system and related commands
Enterprise training and reproduction guidebook - training and reasoning of the OpenPose model based on Huawei ModelArts platform, realizing the recognition of two behaviors of climbing and climbing ov
MySQL - index explanation
MySQL database design specification
UG NX二次开发(C#)-外部模式-导出dwg格式的文件
研发过程中的文档管理与工具
初探形式化方法基本原理
[Unity3D] Beginner Encryption Skills (Anti-Cracking)
MySQL-慢查询日志
(2022 Niu Ke Duo School 5) B-Watches (two points)
MySQL batch update
研发创新编码器霍尔板,引领企业高质量发展
机器学习笔记--数学库
MySQL-底层设置
ROS文件系统以及相关命令
2022-2023 十大应用开发趋势
MySQL常见索引类型