Arguments and Parameters

In programming, functions are used to perform specific tasks and often require input data to do so. The input data is passed to the function as arguments.

In the example given, the function sum takes two arguments, a and b, which are used to calculate the sum of the two values. When the function is called with the values 3 and 5, these values become the arguments passed into the function.

On the other hand, parameters are the variables defined during a function declaration or definition that are used to hold the values passed as arguments. In the sum function, a and b are the parameters defined within the function signature that hold the values passed as arguments during function invocation.

To summarize, arguments refer to the values passed into a function when it is called, while parameters are the variables defined within the function signature that hold these values. In the example given, 3 and 5 are the arguments passed into the sum function, while a and b are the parameters used to hold these values within the function.

function sum(a, b) {
  return a + b;
}

sum(3, 5);

a, b inside function sum( ) are parameters

3, 5 inside sum ( ) are arguments.

Leave a Reply

Your email address will not be published.

ANOTE.DEV