According to freeCodeCamp, functional programming is an approach to software development based around the evaluation of functions. Like mathematics, functions in programming map input to output to produce a result. You can combine basic functions in many ways to build more and more complex programs.
Functional programming follows a few core principles:
-
Functions are independent from the state of the program or global variables. They only depend on the arguments passed into them to make a calculation;
-
Functions try to limit any changes to the state of the program and avoid changes to the global objects holding data;
-
Functions have minimal side effects in the program.
The functional programming software development approach breaks a program into small, testable parts. This section covers basic functional programming principles in JavaScript.
- Learn About Functional Programming
- Understand Functional Programming Terminology
- Understand the Hazards of Using Imperative Code
- Avoid Mutations and Side Effects Using Functional Programming
- Pass Arguments to Avoid External Dependence in a Function
- Refactor Global Variables Out of Functions
- Use the map Method to Extract Data from an Array
- Implement map on a Prototype
- Use the filter Method to Extract Data from an Array
- Implement the filter Method on a Prototype
- Return Part of an Array Using the slice Method
- Remove Elements from an Array Using slice Instead of splice
- Combine Two Arrays Using the concat Method
- Add Elements to the End of an Array Using concat Instead of push
- Use the reduce Method to Analyze Data
- Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem
- Sort an Array Alphabetically using the sort Method
- Return a Sorted Array Without Changing the Original Array
- Split a String into an Array Using the split Method
- Combine an Array into a String Using the join Method
- Apply Functional Programming to Convert Strings to URL Slugs
- Use the every Method to Check that Every Element in an Array Meets a Criteria
- Use the some Method to Check that Any Elements in an Array Meet a Criteria
- Introduction to Currying and Partial Application