Pure Functions and Immutability
Write predictable functions without side effects.
What Is a Pure Function?
A pure function returns the same output for the same input and has no side effects. It does not read or write external state, mutate its arguments, or perform I/O.
A Pure Example
This function depends only on its arguments and produces only a return value. Calling it never changes anything outside.
function add(a: number, b: number): number {
return a + b;
}
console.log(add(2, 3)); // 5, alwaysAll lessons in this course
- Pure Functions and Immutability
- Currying and Partial Application
- Function Composition with Types
- Typed pipe and flow Utilities