Comp 110 Arguments vs. Parameters

Arguments vs. Parameters

  • Extra pieces of information required by the function definition are called parameters. These are like empty variables.
  • The values provided in the function call are called arguments. These are like the variables' values.

Here is an example of how we could call an arbitrary function f.

let f = (a: string, b: number, c: boolean): boolean => {    
     // function implementation would go here!
};
f("aardvark", 57, false);
  • In the example above using function f,
    • Parameters : a: string, b: number, c: boolean
      • located in the function definition!
    • Arguments: "aardvark", 57, false
      • located in the function call!
    • "aardvark" matches with a, 57 with b, false with c

Arguments and parameters must line up via type and purpose 1:1...Remember, functions are like recipes that require specific 'ingredients' (aka arguments) in to produce a final result. If you don't give it the correct ingredients (or not enough/too many ingredients) you will get an error!

Examples of an incorrect call of f:

f(false, "aardvark", 57);
//these arguments don't match the order of the parameters!
f(2, 1);
//too few arguments! This function requires three parameters.