Skip to content
the poor coder

argument and parameter

Poor Man
Published
Reading time
2 min read
On this page

Argument and Parameter#

As a programmer, I understand that argument and parameter are two crucial terms that help in making the code more efficient and reusable. Both of these terms are used to pass values to the function or method in a program.

Argument#

An argument is a value that is passed to a function or method when it is called. In simple words, an argument is a piece of data that a function receives and processes to give back the desired output. Arguments can be of any data type such as integer, float, string, boolean, etc.

Let me give you an example of how arguments work. Suppose we have a function named addNumbers that takes two arguments, x and y, and returns the sum of these two numbers. Here's how we can define this function:

Text

function addNumbers(x, y) {
    return x + y;
}

In this example, x and y are the arguments that are passed to the addNumbers function. When we call this function with two numbers, say 5 and 10, it will return the sum of these two numbers, which is 15.

Text

var sum = addNumbers(5, 10);
console.log(sum); // Output: 15

Parameter#

A parameter is a variable that is used in the function definition to represent an argument that will be passed to the function. In other words, a parameter is a placeholder for an argument that will be passed to the function when it is called.

Let's take the same example of the addNumbers function to understand how parameters work. In this function, x and y are parameters that are defined in the function signature. When we call this function with two numbers, these numbers are passed as arguments to the function and assigned to the parameters.

Text

function addNumbers(x, y) {
    return x + y;
}

When we call this function with two numbers, say 5 and 10, these numbers are passed as arguments to the function and assigned to the parameters x and y.

Text

var sum = addNumbers(5, 10);
console.log(sum); // Output: 15

In this example, x and y are parameters, and 5 and 10 are arguments that are passed to the function.

Conclusion#

In conclusion, both argument and parameter are essential in programming as they help in making the code more reusable and efficient. Arguments are the actual data that is passed to a function when it is called, while parameters are the placeholders for these arguments in the function definition. Understanding the difference between these two terms is crucial for anyone who wants to become a proficient programmer.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC