What Are Functions?
Do you remember the methods we added inside classes?
The idea is similar, but in Functional Programming, functions are the primary building blocks instead of objects.
You can think of every function as following a simple flow:
Input → Processing → Output
A function receives data, processes it, and returns a result.
Example
Suppose we have a word and want to work with it.
const word = "car";
console.log(word.split(""));Although this example is small, it already contains multiple functions.
Built-in Functions
In the previous example, we used two functions provided by JavaScript.
console.log();The log() function prints data to the console.
We also used:
word.split("");The split() function receives a separator and splits the string into smaller pieces.
In this case, it splits the word into an array of individual characters.
You Can Create Your Own Functions
Not every function comes with the programming language.
You can write your own functions to perform any task you need.
For example:
function toUpper(text) { return text.toUpperCase();}
console.log(toUpper("car"));This function receives a string and returns its uppercase version.
This demonstrates the main idea behind Functional Programming: breaking a program into small, reusable functions, each responsible for a single task.
Key Takeaways
- Functions are the foundation of Functional Programming.
- Every function follows the flow: Input → Processing → Output.
- JavaScript provides many built-in functions, such as
log()andsplit(). - You can create your own functions to organize and reuse your code.