JavaScript Functions - Parameters & Arguments Explained
Tags: javascript, functions, arguments, parameters
Published: 2022-02-05 20:56:09

Learn what parameters, arguments, and return statements are with videos and animations.
{% youtube https://youtu.be/MMNDr_U21-0 %}

---

Let’s understand what is a JavaScript Parameter & Argument.
Also what the return statement is.
In the previous article, we learned about the **[general idea of a function, function definition & function invocation.](https://dev.to/deep_space/javascript-functions-explained-part-1-4ldh)**
Visit to refresh your knowledge, if you want.
Let’s get a little more advanced with functions.

---
**Table Of Contents:**

1. JavaScript `Variables in Functions`
2. JavaScript Functions-`Parameters` & `Arguments`
3. JavaScript `return` statement

---

## JavaScript Variables in functions
JavaScript **functions** can also **contain variables**.
Let's create a function called `addNumbers()` to demonstrate.

```
function addNumbers() {
const a = 5;
const b = 10;
const sum = a + b; // 5 + 10
return sum;
}
console.log(addNumbers());

```
**Code Explanation:**
In the function block `{}`, we have 3 variables `a`, `b` and `sum`, with values.
In the end, we have `return` keyword.
Followed by function call `addNumbers();`.

But we can change the above code, using `parameters` & `arguments` to replace variable declaration and assignment.

---

## JavaScript Functions - Parameters & Arguments
JavaScript function `parameters` are the names (placeholders) for values.
JavaScript function `arguments` are the actual values of parameters.

Let me explain it to you like we are having a street conversation, or talk in an informal language.

1. Parameters are variable names. The word **parameter** is just a fancy word for saying **variable name** in JS.
2. Arguments are the actual values of those variables. The word argument is just another fancy word for saying **variable value**
3. So we use parameters(variable names) to refer to argument (variable values)

Makes sense? Let's see it in code, or better convert the above function's variables & their values to parameters & arguments.

```
function addNumbers(a, b) {
const sum = a + b; // 5 + 10
return sum;
}
console.log(addNumbers(5, 10));
```
**Code Explanation:**
Instead of writing variable names inside the function block `{}`.
We wrote them inside the parentheses `()`.
And we gave arguments (actual variable values) on function call `addNumbers(5, 10)`.

Most people can’t see the relationship between parameters & arguments (including myself).
 So I decided to make a video, animations, and pictures to help you visualize.

Notice, we don’t need to use a **JavaScript keyword** `const`, `let` or `var` to declare the variables `a` and `b`, inside the `()` parentheses.

---

## JavaScript return statement
The JavaScript `return` statement as it sounds, it returns something.
When the JavaScript functions reaches the return statement, it will stop the function execution and returns the value to the caller.

---
Thanks for reading, follow me on my [Youtube Channel (Deep Space)](https://www.youtube.com/deepspacex).
And here on the dev community, too.
I love coffee, you can buy me one here "[Buy me a coffee](https://www.buymeacoffee.com/deepspacex)"