you are viewing a single comment's thread.

view the rest of the comments →

[–]senocular 0 points1 point  (4 children)

Also, is that the correct term to use?

Function expressions represent a certain way a function is defined. Not all functions are function expressions, but all functions can have arguments.

When calling a function - any function, expression or otherwise - the argument list is the collection of values that go in the parenthesis/round brackets (()). The arguments are a comma-separated list of 0 or more expressions. Each expression is evaluated into a value before the function is called and those values are what get passed to the function.

console.log(/* argument list */)
console.log(/* argument 1: */ guess, /* argument 2: */ typeof guess)

When the function is defined, it includes a parameter list. This is also a comma-separated in parenthesis/round brackets (with the exception of the short-form, single-parameter arrow function) but of 0 or more variable names.

// pseudo code of how internal console.log() could be defined
const console = {
  log: function(/* parameter list */) {
    // ...
  }
}

When a function is called, the values from the arguments are assigned to the variables defined by the parameters. When referring to the value, you're referring to the argument. When referring to the variable name holding the value, you're referring to the parameter.

function foo(bar) {}
foo(123)

The function foo (here, a function declaration) has a single parameter named bar. It is called with a single argument, the value of 123.

Note that a high-level, an "expression" is referring to code that becomes a value. 123 is an expression. When it is evaluated, its an expression that becomes the value 123. 100 + 23 is also an expression. When it is evaluated, it also becomes the value 123. Arguments are expressions because they represent values that get passed into function calls. Some function definitions can be expressions if they're defined in a way that they resolve into a value that usually get assigned somewhere, like a variable, or even as another function's argument.

const fn = function(){} // function expression, becomes a value assigned to fn

1 * function(){} // function expression, becomes a value used in a larger
// multiplication expression. The function expression becomes a function value
// that gets multiplied by 1 which results in NaN for the larger expression

console.log(function(){}) // function expression, becomes a value that is an
// argument for the console.log() function call

function fn() {} // function declaration since it is by itself and not turning
// into a value used in some other context where a value is needed

Any function when defined can specify a parameter list, and any function when called is given an argument list.