Logo

Developer learning path

JavaScript

Parameters and Arguments in JavaScript

Parameters and Arguments

78

#description

In JavaScript, functions can accept input values called parameters when they are defined. Parameters are defined inside the parentheses after the function name, and they act as placeholders to receive data when the function is called.

For example:

                    
function calculateArea(width, height) {
  return width * height;
}
                  

In the above example, the calculateArea() function has two parameters, width and height. When we call the function and pass values for width and height as arguments, the function will use those values to perform some actions and return a result.

                    
let area = calculateArea(5, 7); //area will be 35
                  

In this example, we are calling the calculateArea() function and passing the values 5 and 7 as arguments. These values are then received by the parameters width and height inside the function, and the function performs the multiplication operation to calculate the area, which is returned and assigned to the area variable.

In essence, parameters are like placeholders that tell a function what values to expect as input, while arguments are the actual values passed to the function when it is called.

March 25, 2023

If you don't quite understand a paragraph in the lecture, just click on it and you can ask questions about it.

If you don't understand the whole question, click on the buttons below to get a new version of the explanation, practical examples, or to critique the question itself.