What is the use of Parentheses in a function?

What is the use of parentheses in a JavaScript function? I am super confused. I am not very clear about it.

I think you can find all your answers inside the functions documentation page.

Looking at an extract for it:

A function definition (also called a function declaration , or function statement ) consists of the function keyword, followed by:

  • The name of the function.
  • A list of parameters to the function, enclosed in parentheses and separated by commas.
  • The JavaScript statements that define the function, enclosed in curly brackets, {...} .

For example, the following code defines a simple function named square :

function square(number) {
  return number * number;

Hope it helps :sparkles:

1 Like

Hi Brijesh,
parentheses are used to store arguments that the function will work with. I’ll give you some examples:

function myFunction(name){
        console.log("Hello, my name is "+name)
////The result will be "Hello, my name is Brijesh" written in a console./////

As you can see, we have put a “name” argument inside those parentheses when we created the function so our function always writes "Hello, my name is " and then the name that you provide when calling the function later in the code.

function mySecondFunction(num1,num2){
      var sum = num1+num2;
console.log(mySecondFunction(2,3)  //// Result will be 5

In this function, we put 2 arguments, and the function operates with them

1 Like

Thanks a Great Deal @Marmiz and @veljkocukic