参数

参数是在 函数定义中声明的命名变量。它们用于引用传递给函数的 实参

例如

js
const argument1 = "Web";
const argument2 = "Development";
example(argument1, argument2); // passing two arguments

// This function takes two values
function example(parameter1, parameter2) {
  console.log(parameter1); // Output = "Web"
  console.log(parameter2); // Output = "Development"
}

参数有两种类型

输入参数

最常见的一种;它们将值传递给函数。根据编程语言的不同,输入参数的传递方式有几种(例如,值传递、地址传递、引用传递)。

输出/返回参数

主要用于从函数返回多个值,但不推荐使用,因为它们容易引起混淆

参数与实参的区别

请注意 参数实参 之间的区别

  • 函数参数是列在函数定义中的名称。
  • 函数 实参 是传递给函数的实际值。
  • 参数被初始化为所提供实参的值。

另见