Arguments
A parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the method's parameters. To say it again, a parameter is the variable in the declaration of the function. An argument is the actual value of this variable that gets passed to function.
File Location
Let's work in this file:
Sample Code
Let's create a function with three parameters:
Let's pass in arguments to satisfy those parameters:
A few more rules on arguments and functions: 1. Extra argument get ignored:
If an argument hasn't been provided, it's NaN.
The Arguments Object
The arguments object is a local variable available within all (non-arrow) functions. You can refer to a function's arguments within the function by using the arguments object. arguments
is a keyword, and it is array-like, which means that the object is indexed, starting at 0. Take some time to type the following demoFunction
and analyze it's interworkings:
More Practice
The most important takeaways here are this:
Know the difference between a parameter and an argument.
Know about the
arguments
object found inside of functions.
Last updated