Create a Function with Appended Partials in JavaScript Last Updated : 04 Nov, 2025 Comments Improve Suggest changes 2 Likes Like Report In JavaScript, partial functions let you predefine some arguments of another function and call it later with remaining ones, making code cleaner and reusable.Partial application predefines some arguments of a function for later use.Uses the spread (...) operator to handle fixed and dynamic arguments.Helps create reusable and simplified versions of complex functions.[Approach 1]: Using the Spread Operator to Append PartialsWe want to implement a function that invokes another function and provides the arguments it received.We can get the result by using (...) the spread operator.Create a main function (math) that passes received arguments to another function.The first argument is the target function name; the rest (...params) are its parameters.Use the spread operator (...params) to call the target function with those arguments.Define helper functions like sum, sub, mul, and pow to perform operations using the passed arguments. JavaScript // Function "math" responsible for // passing the arguments const math = (functionName, ...params) => functionName(...params); //function to add all passed arguments const sum = (...args) => { var result = 0; for (const val of args) { result += val; } console.log(result); } // Function to subtract all // passed arguments const sub = (...args) => { var result = 0; for (const val of args) { result -= val; } console.log(result); } // Function to multiply all // passed arguments const mul = (...args) => { var result = 0; for (const val of args) { result *= val; } console.log(result); } // Call to the functions via "math" math(sum, 2, 3, 4, 5, 6); math(sub, 5, 4, 1); math(mul, 2, 3, 5, 6); Output: The math function has successfully called the other functions and appended the required arguments. 20 -10 0[Approach 2]: Using Rest Parameters for Partial Applicationfollowing example demonstrates a function that uses the first two arguments. It has used the first two arguments and our "args" is referring to the rest of the arguments leaving the first two arguments. JavaScript const fun = (arg1, arg2, ...args) => { console.log(args); } fun(1, 2, 3, 4, 5, 6); Output:[ 3, 4, 5, 6 ] Create Quiz Comment J jymnjogiya Follow 2 Improve J jymnjogiya Follow 2 Improve Article Tags : JavaScript Web Technologies javascript-functions javascript-operators JavaScript-Questions +1 More Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like