当前位置:网站首页>学习笔记(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 */
作用域:每一个参数都有一个作用范围,超过范围就失效,这个范围就叫作用域。
边栏推荐
- The best interests of buying and selling stocks with handling fees [What is missing in the definition of DP status?]
- FormData upload binary file, object, object array
- Visual Analysis of DeadLock
- LeetCode 283. Shifting Zeros (Simple, Array)
- postgres groupby 合并字符串
- flutter 自己写一个组件
- Splunk Filed extraction field interception
- Inverter insulation detection detection function and software implementation
- regular expression
- PanGu-Coder: A function-level code generation model
猜你喜欢
随机推荐
OC-NSDictionary
View zombie processes
WebForm DropDownList分别绑定年月
postgres groupby merge strings
LeetCode 2360. 图中的最长环
HCIP 第六天
Introduction to Totem Pole and Push-Pull Circuits
playwright 爬虫使用
Mysql报错2003 解决办法 Can‘t connect to MySQL server on ‘localhost‘ (10061)
The best interests of buying and selling stocks with handling fees [What is missing in the definition of DP status?]
spark架构
A full review of mainstream timed task solutions
HCIP 第五天
HCIP 第四天
Comprehensive experiment of MPLS and BGP
HCIP 第八天
有点奇怪!访问目的网址,主机能容器却不行
MPLS和BGP的综合实验
Find the largest n files
Link with Game Glitch









