# 章序号/节序号/节/笔记序号 codecademy,function # 概念阐释 ### 行参 - 需要函数执行特定的任务时需要在声明函数时提供**行参parameters,行参的行为类似于变量**。 ![](http://image.harryrou.wiki/2023-01-31-%E6%88%AA%E5%B1%8F2023-02-01%2007.38.47.png) ### 值作为实参 - 调用带有行参的函数时,需要在调用函数的括号内指定一些值,**这些值叫做行参,就像变量名需要赋值**。 ![](http://image.harryrou.wiki/2023-01-31-%E6%88%AA%E5%B1%8F2023-02-01%2007.48.50.png) ### 变量名作为实参 - 不一定在调用函数时直接写值,也可以在`()` 中使用变量。 ![](http://image.harryrou.wiki/2023-01-31-%E6%88%AA%E5%B1%8F2023-02-01%2007.44.53.png) # 举例子 ![](http://image.harryrou.wiki/2023-02-01-%E6%88%AA%E5%B1%8F2023-02-01%2008.04.27.png) ![](http://image.harryrou.wiki/2023-02-01-%E6%88%AA%E5%B1%8F2023-02-01%2013.18.39.png) # 类比、比较与对比 - 行参=变量名 - 实参=变量值 - 实参=新的(有值的)变量名 # 问题 [练习题](https://www.codecademy.com/courses/introduction-to-javascript/lessons/functions/exercises/parameters) **1.** The `sayThanks()` function works well, but let’s add the customer’s name in the message. Add a parameter called `name` to the function declaration for `sayThanks()`. **2.** With `name` as a parameter, it can be used as a variable in the function body of `sayThanks()`. Using `name` and string concatenation, change the thank you message into the following: ``` 'Thank you for your purchase '+ name + '! We appreciate your business.' ``` Copy and paste the above message into your code. **3.** A customer named Cole just purchased something from your online store. Call `sayThanks()` and pass `'Cole'` as an argument to send Cole a personalized thank you message. # 问题答案 ```js function sayThanks(name) { console.log('Thank you for your purchase '+ name + '! We appreciate your business.');//行参相当于变量名 } sayThanks('Cole');//实参相当于变量值 ``` # 备注(经验集/错误集)