引數
引數是作為輸入傳遞給 函式 的 值(原始值 或 物件)。請勿將引數與 形參 混淆,形參是在函式定義中用於引用引數的名稱。
例如
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
}