Course contentsShow
← JavaScript
Lesson 478 of 2,72312. Higher-Order FunctionsFree lesson

Manual Composition with Nested Calls

Writing composed functions by hand using nested function calls and their readability challenges.

Manual Composition with Nested Calls

What you'll learn: How to combine multiple functions by calling them inside each other, and why this quickly becomes hard to read.

The Core Idea

When you compose functions manually, you nest function calls inside one another. The output of one function becomes the input to the next. While this works perfectly fine from JavaScript's perspective, it creates a readability problem: you have to read the operations inside-out or right-to-left, which is the opposite of how we naturally think.

const add10 = x => x + 10;
const double = x => x * 2;
const square = x => x * x;

// Manual composition: nested calls
const result = square(double(add10(5)));
// 5 → add10 → 15 → double → 30 → square → 900

The Readability Challenge

To understand what's happening, you must start at the innermost function (add10(5)) and work your way outward. This is counterintuitive because:

  • We read left-to-right
  • We think in sequential steps
  • The visual order is backwards from the execution order
// What it looks like:  square → double → add10
// What actually happens: add10 → double → square
const result = square(double(add10(5)));

As you add more functions to the composition, the nesting becomes deeply uncomfortable:

// Very hard to parse!
const result = funcE(funcD(funcC(funcB(funcA(value)))));

This is why developers created better patterns for composition—but understanding this manual approach shows you why those patterns exist.

Key Takeaway: Manual composition using nested calls works but forces you to read inside-out, making complex chains difficult to understand and maintain.