参数

参数是作为输入传递给 函数原始值对象)。请勿将参数与 形参 混淆,形参是在函数定义中用于引用参数的名称。

例如

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"
}

函数调用中的参数顺序应与函数定义中的形参顺序相同。

js
const argument1 = "foo";
const argument2 = [1, 2, 3];
example(argument1, argument2); // passing two arguments

// This function takes a single value, so the second argument passed is ignored
function example(parameter) {
  console.log(parameter); // Output = foo
}

另见