JavaScript Function Parameters Last Updated : 17 Dec, 2024 Comments Improve Suggest changes Like Article Like Report Function parameters are variables defined in the function declaration that receive values (arguments) when the function is called. They play a key role in making functions reusable and dynamic.Values are assigned to parameters in the order they are passed.You can assign default values to parameters if no arguments are provided.Allows capturing an indefinite number of arguments into an array.Primitive types are passed by value, whereas objects are passed by reference. JavaScript function greet(name) { return `Hello, ${name}!`; } console.log(greet("Meeta")); OutputHello, Meeta! Parameter: name in the function definition.Argument: "Meeta" passed when calling the function.Types of Parameters in JavaScript1. Required ParametersThese are the basic parameters expected by the function. If not provided, they will be undefined. JavaScript function add(a, b) { return a + b; } console.log(add(5, 3)); console.log(add(5)); Output8 NaN 2. Default ParametersIntroduced in ES6, default parameters allow you to assign a default value to a parameter if no argument is passed or if the argument is undefined. JavaScript function mul(a, b = 1) { return a * b; } console.log(mul(5)); console.log(mul(5, 2)); Output5 10 3. Rest ParametersRest parameters allow a function to accept an indefinite number of arguments as an array. Use the ... syntax to capture all additional arguments. JavaScript function sum(...numbers) { return numbers.reduce((total, num) => total + num, 0); } console.log(sum(1, 2, 3, 4)); Output10 4. Destructured ParametersYou can destructure arrays or objects passed as arguments into individual variables. JavaScript function displayUser({ name, age }) { return `${name} is ${age} years old.`; } const user = { name: "Meeta", age: 25 }; console.log(displayUser(user)); OutputMeeta is 25 years old. 5. Passing Functions as Parameters (Higher-Order Functions)Functions in JavaScript can accept other functions as parameters, making it easy to create reusable code. JavaScript function executeTask(task, callback) { console.log(`Task: ${task}`); callback(); } executeTask("Clean the room", () => { console.log("Task Completed!"); }); OutputTask: Clean the room Task Completed! Comment More infoAdvertise with us Next Article JavaScript Function Parameters R rathbhupendra Follow Improve Article Tags : JavaScript Web Technologies javascript-functions Similar Reads JavaScript Rest parameter The JavaScript Rest parameter allows a function to accept an indefinite number of arguments as an array. It is represented by three dots (...) followed by the parameter name and must be the last parameter in the function, enabling flexible and dynamic argument handling.Syntax//... is the rest parame 4 min read JavaScript Function length property The Javascript Function.length property of the function object in Javascript is used to return the number of parameters required by a function. Syntax: function.length Parameters: This method requires no parameters. Return: Return type is number. A few examples are given below for a better understan 2 min read Functional programming in JavaScript Functions are the most important part of functional programming (especially in JavaScript). Functions are the single source that helps developers to perform functional programming. Generally abbreviated as FP which revolves around functions and it is how we use functions that makes our code function 7 min read Argument vs Parameter in Java Argument An argument is a value passed to a function when the function is called. Whenever any function is called during the execution of the program there are some values passed with the function. These values are called arguments. An argument when passed with a function replaces with those variabl 2 min read JavaScript Function Complete Reference A JavaScript function is a set of statements that takes inputs, performs specific computations, and produces outputs. Essentially, a function performs tasks or computations and then returns the result to the user.Syntax:function functionName(Parameter1, Parameter2, ..) { // Function body}Example: Be 3 min read Like