JavaScript Function Parameters
Last Updated : 1 Dec 2025
In JavaScript, function parameters are the variables that are used as arguments when calling a function. Function parameters are used to pass data into the function and allow the function to process it.
In JavaScript, the function parameters can be passed by value or by reference.
- Passed by value: When a parameter is passed by value, the function creates a copy of the parameter and uses the copy to process the data.
- Passed by reference: When a Parameter is passed by reference, the function uses the actual parameter in the function, and any changes made to the parameter will be reflected in the original parameter.
JavaScript function parameters are declared inside the parentheses of the function declaration.
Syntax
The syntax of a function parameter in JavaScript is as follows:
Rules of Parameter
JavaScript function definitions do not require the specification of parameter data types.
In JavaScript, it is unnecessary to specify the data type for function parameters.
The JavaScript compiler does not conduct type-checking on the arguments passed to functions.
Output:
Hello, Alice! Hello, Bob!
Default Parameter
Default parameters in JavaScript allow named parameters to be initialized with default values if there is no value or undefined is passed. You can use the equal sign (=) and the value to initialize a parameter while declaring the function.
Example
Function Rest Parameter
Rest parameters in JavaScript are a feature introduced in ES6 that allows us to pass an indefinite number of arguments to a function.
JavaScript rest parameters can be used to pass unlimited arguments to a function, and the rest parameter enables us to access those arguments as an array.
Output:
Argument Object
In JavaScript, each function can have an argument object. It contains all passed arguments while invoking the function in the array format. In JavaScript, you can traverse through the array and get each argument even if the function's parameters are not specified.
Output:
Number of arguments: 3 Argument 0: Welcome to Tpointtech Argument 1: 321 Argument 2: true Number of arguments: 1 Argument 0: Only one argument Number of arguments: 0
Passing Arguments by Value
In a JavaScript function, when you pass the argument by value to a function call, it sends the argument value to the parameter of the function definition. So, when you update the function parameter, the function parameter doesn't change the original value.
Output:
Before function call: 10 Inside function, before change: 10 Inside function, after change: 20 After function call: 10
Passing Arguments by Reference
In a JavaScript function, when we pass objects as arguments, the function sends the address of the object as a parameter to the function definition. Therefore, it is said that the arguments are passed by reference.
When you change an object's property within the function body, the change will also be reflected outside the function.
Output:
Before function call: { name: 'Alice', age: 25 }
Inside function: { name: 'Alice', age: 26 }
After function call: { name: 'Alice', age: 26 }