π 3.1.0.1 Functional Programming with JavaScript Objectives
Up to this point, we have focused on object-oriented programming. However, there are other paradigms beyond object-oriented programming. One of the most useful and popular paradigms is functional programming. In this section, we will focus on learning how to program using a functional approach.
Having at least a basic understanding of functional programming is essential to progressing as a developer. Moreover, functional programming patterns are foundational to React.
Good news: you've already been doing some functional programming! Every time you've used map() or filter(), you were using FP techniques. This section will help you understand these patterns more deeply and use them intentionally.
In this course section, we'll cover the following:
| Concept | What It Means | Why It Matters |
|---|---|---|
| Pure functions | Functions that always return the same output for the same input | Easier to test and debug |
| Immutability | Never modifying existing data | Prevent unexpected bugs |
| Array methods | map(), filter(), reduce() | Clean, readable data transformations |
| Closures | Functions that "remember" variables from their outer scope | Foundation for many patterns |
| Function factories | Functions that create other functions | Reusable, configurable code |
| Composition | Building complex functionality from simple pieces | Flexible alternative to inheritance |
| Recursion | Functions that call themselves | Elegant solutions to certain problems |
Some of these concepts can feel abstract at first. That's normal. You don't need to master everything immediately - focus on building familiarity and getting practice.
How This Differs from OOPβ
| Object-Oriented | Functional |
|---|---|
| Focuses on what things are (a User, a Game) | Focuses on what things do (transform data, calculate values) |
| Organizes code into classes with methods | Organizes code into small, reusable functions |
| Often mutates object state | Avoids mutation; creates new values |
| Uses inheritance to share behavior | Uses composition to combine behaviors |
Professional developers use both paradigms. The goal isn't to abandon OOPβit's to add functional techniques to your toolkit and know when each approach fits best.
Testingβ
You're expected to write tests for all your functions throughout this section. See A Note on Testing for details on what to expect and setup references if you need them.
Independent Project Objectivesβ
For this course section, the independent project will be different from previous weeks. You will spend your normally scheduled independent project time brainstorming and preparing an idea for your Capstone project. The Capstone project is a larger project that you'll spend a majority of the final course crafting, with the intention that you will be able to leverage this project to showcase your skills to employers, and explore ideas and concepts that you're interested in that haven't been covered in classes.
Keep in mind that you're not beholden to any ideas you come up with at this point. The main goal we have with this section is to get you thinking about project ideas early on, and teachers will be able to provide you with feedback and advice to help you approach your most successful ideas later on.
For this first Capstone exploration, the objectives are fairly simple:
- An idea board(s) to show us your thought process and what other project ideas you considered
- Includes a one page outline of capstone project.