JS 参数与参数

JS arguments vs parameters

不同的来源以不同的方式解释它。 在下面的示例中,哪些是参数,哪些是参数?

 const add = function(number1, number2){
       return number1 + number2
           }

    add(3,10)

谢谢!

编辑:正如另一位用户所指出的,这是重复的。 What is the difference between arguments and parameters in javascript?


参数是在运行时传递给函数的内容。参数是在函数定义中定义的,并且是参数的别名。

Parameters are variables listed as a part of the function definition.

Arguments are values passed to the function when it is invoked.

来源:https://codeburst.io/parameters-arguments-in-javascript-eb1d8bd0ef04

function moo(number1, number2) {} // parameters are defined

moo(10, 50, 100); // arguments are passed.
// notice that more than the specified number of parameters
// can be supplied and accessed via 'arguments'

另见 arguments:

arguments is an Array-like object accessible inside functions that contains the values of the arguments passed to that function.

参数是作为函数定义的一部分列出的变量。参数是调用函数时传递给函数的值。

const add = function(number1, number2){ //Arguments
   return number1 + number2 //Parameters
       }

add(3,10)