Parameters or arguments in programming functions are values that are passed to a function from outside of it and that the function receives and can use and process.
Remember that a function is an independent piece of code that performs a task. To do this, it can receive a series of inputs and have an output.

Parameters are the inputs that the function can receive. They are a very powerful tool that allows our functions to be much more reusable (than if they didn’t exist).
In general, function parameters look like this.
function myFunction(parameter1, parameter2, parameter3)
{
// function body
}
Parameters can be of different data types depending on the language we are using, such as numbers, strings, objects, or collections.
Examples of Parameters in Functions in Different Languages
Let’s see examples of how to define a function in different languages that receives parameters. For the example we are going to create a sum function.
function add(a, b)
Basically, we want a function that receives two numbers as parameters, calculates their sum, and then would do something with them (we omit the “something to do” for the example, because the important thing now are the parameters).
It’s a very simple function, which probably wouldn’t even make sense to define in a real program. But it’s good for illustrating the syntax of parameters.
This is how an example would be done in C, C++, C# or Java. In this case, the parameters are placed between parentheses in the function definition, separated by commas. Since it’s a strongly typed language, it’s necessary to specify the type of each parameter, which in our example is int.
// Function definition
void add(int a, int b) {
int result = a + b;
// here we would do something with result, like displaying it on screen
}
// call the function
add(3, 5);
The syntax in JavaScript is similar, the parameters are indicated between parentheses in the definition, separated by commas. However, being a dynamically typed language, it’s not necessary to indicate the parameter types.
// Function definition
function add(a, b) {
let result = a + b;
// here we would do something with result, like displaying it on screen
}
// call the function
add(3, 5);
In the case of, for example, TypeScript the syntax is similar to JavaScript. But, TypeScript is typed, so again it’s necessary to indicate the types. In this case, they are placed after the variable name, separated by :.
// Function definition
function add(a: number, b: number) {
let result = a + b;
// here we would do something with result, like displaying it on screen
}
// call the function
add(3, 5);
In the case of Python, we see it’s very similar to the previous ones. Python is a dynamically typed language, so again it’s not necessary to indicate the parameter types.
# Function definition
def add(a, b):
result = a + b
# here we would do something with result, like displaying it on screen
# call the function
add(3, 5)
To give an example of a somewhat more “bizarre” language, this is what a function would look like in SQL. Apart from the syntax being somewhat horrible, basically, the function parameters are again indicated between parentheses, indicating the variable name and its type.
CREATE FUNCTION add(@a INT, @b INT)
BEGIN
DECLARE @result INT;
SET @result = @a + @b;
-- here we would do something with result, like displaying it on screen
END;
As we can see, apart from syntax differences between languages, and some requiring the parameter types to be indicated and others not, the definition and concept are the same in all languages.
Best Practices Tips
It is important to keep in mind that a function should not have an excessive number of parameters. If a function has too many parameters, it can become difficult to understand and maintain.
It is recommended that if a function has more than three or four parameters, it’s better to consider passing a grouping of elements as a parameter.
For example, imagine a function that prints a PDF document, and receives a bunch of options.
function PrintPDF(document, landscape, papersize, orientation, singleface, ...) {
}
It would probably be cleaner if we wrap all the options in a grouping containing all the options.
function PrintPDF(document, options) {
}
