![The Hard Parts of Functional JavaScript](https://static.frontendmasters.com/assets/courses/2019-10-01-functional-js-fundamentals/thumb.webp)
Check out a free preview of the full The Hard Parts of Functional JavaScript course
The "Functional Programming Benefits & Concepts" Lesson is part of the full, The Hard Parts of Functional JavaScript course featured in this preview video. Here's what you'd learn in this lesson:
Will briefly explains the different concepts of functional programming that will be explored in depth during the course. The advantages of functional programming are also discussed.
Transcript from the "Functional Programming Benefits & Concepts" Lesson
[00:00:00]
>> Will Sentance: But take a look at this. We can produce a beautiful to do list of our code. Here it is. Here in our quiz game, we've taken in an object here with the name Will and score three and we grabbed the player's name. We then take their first name.
[00:00:21]
We're then gonna properCase it. We're then gonna prepend a label saying this is a user. We're then gonna create a dom element or a an element ready with that data in it. And we can then take that and render it to the web page. And people, look at the beauty of this.
[00:00:40]
Look at this beautiful readable style of code. No mysteries here what our code is actually doing. But to do so is gonna require us to wrangle our code out of the mini baby blocks of code, our little mini functions in some pretty interesting ways. It's gonna require us to rejoin those lines of code up into full size tasks.
[00:01:04]
We see a preview of it here. We're gonna make sure that those little blocks of code are really reusable. Once you break the task down to little baby steps, you can actually reuse those steps all over the place. But if you're gonna be reusing them all over the place, you probably wanna make sure they're independent of anything around them.
[00:01:21]
And that's exactly what we're gonna have to do today. We're gonna start off with higher order functions, and function composition. As I said, all those little atoms of code can be reused all over the place. How we combine them up is gonna depend on higher order functions and function composition.
[00:01:38]
Most of those tasks, things like implementing a number, looping through an array, they're typical tasks. We can couple them up again. Use them again. Write them once, keep it dry, don't repeat yourself. Use them again.
>> Will Sentance: As I say, if we're not going to be using that functionality once in one place, but all over the place, well, we better hope that they're independent and not relying on bits of data outside of them.
[00:02:03]
We're gonna need to understand purity of functions and state immutability. And if we're gonna be coupling up code and have those perhaps be running one after another, not controlled by us but controlled by some other functions, we may need to do some pretty interesting things that adjust our existing saved functions.
[00:02:29]
Maybe give them extra powers. Function decoration with the help of closure and partial application with the help of closure are gonna be our main techniques. But if we can do it, we're gonna end up with code that is more readable. Every single line, so beautiful. I know exactly what it's doing, easy to debug.
[00:02:55]
Every single line nicely labeled, and an individual unit whose only consequence is gonna be on the next slide, not the rest of the application. No mysteries of what each line does and the risk of it damaging the rest of our app. And easy to add features. We take these little baby functions, these little baby units, we combine them all back up.
[00:03:15]
We don't have to rewrite the components. We're just drawing up pre-written components. And that's exactly what we're gonna see today. It's gonna allow us to build out applications where functions are reusable, versatile, flexible little portions of code, independent, self contained and predictable steps, passing data from one to the next to the next to the next.
[00:03:39]
But it all starts with us being confident with the core principles of JavaScript.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops