> For the complete documentation index, see [llms.txt](https://edsonha.gitbook.io/my-gitbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edsonha.gitbook.io/my-gitbook/object-oriented-programming-oop/oop-vs-fp.md).

# OOP vs FP

The beauty of JS is that it is multi paradigm we can use both of these techniques that better suited to solve problems.

The basis of FP is Closure and the basis for OOP is Prototypes.

![Small pieces combined create desired output. We can add more the future, if need](https://2299818979-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnQNlsYsgke3L_g2vbZ%2F-LsQFEtHmtfm4Gw_oUga%2F-LsQFXizEaj7VnZUvr1h%2FComposition.jpg?alt=media\&token=51d576a9-689d-42b7-8b19-896e55550530)

![A superclass that is extended to smaller pieces that add or overwrite things.](https://2299818979-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LnQNlsYsgke3L_g2vbZ%2F-LsQFEtHmtfm4Gw_oUga%2F-LsQFTEvUVNA8fF5AkGD%2FInheritance.jpg?alt=media\&token=1f2b9861-eeea-4460-a3b9-1c07f870a7cb)

|                   FP                   |               OOP              |
| :------------------------------------: | :----------------------------: |
| Many different operation on fixed data |  Few operation on common data  |
|     Stateless - State is immutable     | Stateful - State is modifiable |
|          Pure - No side effect         |           Side effect          |
