Predictable Code

Functional Programming (FP) teaches us to write code so it's easy to test and understand.

1. Pure Functions

  • They always return the same result for the same inputs.
  • They have no side effects (they don't change external variables, don't log to the console, don't make network requests).

2. Immutability

Instead of mutating an old object, a function returns a new one with the changes applied.

Note

Using pure functions makes your code " transparent " . You can replace a function call with its computed result, and nothing will break.

Tip

Try to write the core of your logic using pure functions, and push all " dirty " actions (DOM, APIs) to the edges of your program.