5 Advanced JavaScript concepts that will make you a better developer

Henrik Larsen Toft
Level Up Coding
Published in
3 min readMay 24, 2022

--

Photo by Arnold Francisca on Unsplash

Currying

Currying means evaluating functions with multiple arguments and decomposing them into a sequence of functions with a single argument. So, instead of taking all arguments at once, the function takes the first argument and returns a new function, which takes second argument and returns a new function, which takes the third… and so on until all arguments are provided and the final function is executed.

Currying helps you divide functions into smaller reusable functions that handle a single responsibility. This makes your functions more pure, less prone to errors and easier to test.

In the above example, we created our own simple implementation for currying a function with exactly three parameters. As a general solution, I suggest using Ramda or similar which supports currying functions with any number of arguments and also with support for changing order of arguments using placeholders.

Composition

Composition is a technique where the result of one function is passed on to the next function, which is passed-on to the next function, and so on… until the final function is executed and some result is computed. Function compositions can be composed of any number of functions.

Composition also helps split functions into smaller reusable functions the has a single responsibility.

Ramda also has APIs for function composition with pipe and compose.

Closures

A closure is a function that preserves access to vars and arguments (the scope) of the outer function, even after the outer function has finished executing. Closures are useful for hiding implementation detail in…

--

--