Invocation Expressions
An invocation expression is JavaScript’s syntax for calling (or executing) a function or method. It starts with a function expression that identifies the function to be called. The function expression is followed by an open parenthesis, a comma-separated list of zero or more argument expressions, and a close parenthesis. Some examples:
f(0)// f is the function expression; 0 is the argument expression.Math.max(x,y,z)// Math.max is the function; x, y and z are the arguments.a.sort()// a.sort is the function; there are no arguments.
When an invocation expression is evaluated, the function
expression is evaluated first, and then the argument expressions are
evaluated to produce a list of argument values. If the value of the
function expression is not a callable object, a TypeError is thrown.
(All functions are callable. Host objects may also be callable even if
they are not functions. This distinction is explored in Callable Objects.) Next, the argument values are assigned,
in order, to the parameter names specified when the function was
defined, and then the body of the function is executed. If the
function uses a return statement to
return a value, then that value becomes the value of the invocation
expression. Otherwise, the value of the invocation expression is
undefined. Complete details on function invocation, including an explanation of what happens when the number of argument expressions does not match the number of parameters in the function definition, ...