Javascript functions

Hi, help!
I have a general question since the start of the lesson on functions (javascript). I figured ill eventually figure out why and when we include the subject in the parameter of a function. If someone could clearly explain when do we mention the parameter before the curly braces or just leave it as (). My question is when do I leave the parenthesis empty or when do i have to fill it with values?

Hello @ehsanity.

When you fill the parentheses, you are providing parameters for the function. These can then be used throughout the function, as copies of the data you put in. For example, if you wanted to take a number and multiply it by 2, you would use a parameter, as this allows the number to be anything:

function multiply(x) {
return x * 2; //x can be provided any number value, and this will still work

You can do some more reading about parameters here.

If you don’t want any parameters, then you put the () to tell JavaScript that you are writing a function, and it tells JavaScript that you are calling a function when you call the function:

someFunction()//if this was defined, it would now execute the 
//function's code

Here is some more reading on it.
I hope this helps!

1 Like