Home > Web Front-end > JS Tutorial > Currying in JavaScript

Currying in JavaScript

Barbara Streisand
Release: 2024-12-31 10:54:15
Original
345 people have browsed it

Currying in JavaScript

Currying is the pattern of writing the functional code more modular. In simple words.

Currying is the pattern where a function with multiple arguments is transformed into a series of functions, each taking a single argument.

Instead of taking all arguments at once, the curried function takes the first argument, returns a new function that takes the next argument, and so on until all arguments are provided. The final function then returns the result.

//Normal Function
 `function nonCurrying(param1, param2, param3){
  return param1 + param2 + param3
}`

// Curried Function

`function curried(param1){
   return function(param2){
    return function(param3){
      return param1 * param2 * param3
}}}

curried(10)(20)(30);
`





Copy after login

The above is the detailed content of Currying in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template