Functional Programming in JavaScript is more like a style, rather than a paradigm. This JavaScript Functional Programming Tutorial was made to demonstrate it’s simply writing your code in a chained, clean and efficient way. Doing this can reduce your 50-100 lines of code to just a few without sacrificing readability and logical integrity.
Relevant keywords, it seems:
functional programming javascript
functional programming vs object oriented
functional patterns
functional programming patterns
functional programming concepts
Follow on Twitter: https://twitter.com/js_tut
Learning Curve Books: http://www.learningcurvebook.net
Instagram: https://www.instagram.com/javascriptteacher
Facebook: https://www.facebook.com/javascriptteacher
Original source
15 responses to “JavaScript Functional Programming Tutorial”
You have shown the very basics of JavaScript functional programming in so simple a way that it clears so many confusions moving around the subject. For any code its conciseness and clarity are of prime important. Thank you for sharing. 😃👍
I personally believe that ‘const’ should always be used now to remplace ‘var’ in any case with no exception and in the rare case when you will need to reassign a primitive value which is not passed by reference then in that context it would be the only exception to use ‘let’ instead
I don’t think the whole value of Functional programming to save space and reduce number of lines. It should be more than that. For this sole reason I had to dislike the video. 😐
8:50 please remove the curly brackets { } otherwise, it won't return it, it just won't work 😉
You've got a new subscriber <3
@4:49 am i correct in saying that when we are not changing the state unpredictably, by ensuring we have pure functions that do not change this state unpredictably, we are achieving the desired result of functional programming?
The downside is that you can also take this sort of programming too far, producing an endless chain of maps, filters, reducers, and whatever else. Your example is nice and clean because your data is extremely simplify and you're only performing a couple of operations.
I've seen some horrific balls of spaghetti mess written this way.
Imo programmers are too obsessed with reducing the lines of code. There is much to be said about breaking the code down to a few extra lines for readability. Less code is not always better.
Thank you very much! – It is very sad how Ruby is so overlooked Yukihiro Matsumoto already added all these feature in the language that JS and Java and others adopted recently.
How can I write this snippet in FP-way?
if(a) {
let b = getFrom(a);
if(b) {
proceed(b)
} else {
done()
}
} else {
done()
}
Your introduction was very perfect….as I was also looking for technical concepts of functional programming than its definition 🙂
Thanks for your clean and understandable video.
Is important to highlight that when u write something like this "add = item =>{ item+1 };" is not the same as if u write it like this "add = item => item+1;" because in the first case u are not actually returning anything but in the second way u are returning the new item, so the second way is cleaner but you also implicitly return the new value
If your array L = [2,3,4] and you calculating var val by applying to L function add_one to each item and than reducing the result by summarizing all items in it, than your val should equal 12. Not 9! Did you start with L=[1,2,3]? or L=[2,3,4]?
That's a great way to take something so simple as For loop and turn it into unreadable and incomprehensible bunch of functions 😀 Well now i know that i don't like functional programming. But i learned something new and am enjoying your tutorials. Thanks! Keep it up.
An introduction to writing
elegant, readable and maintainable code.
Great lesson, as usual. Thank you for your effort.
This is not an introduction to functionnal programming but just an introduction to map/reduce. Let's stop defining FP as map/reduce/filter, these are just a small part of what FP is.
Also, an arrow function is not like a function, it is mostly like a function. We need to stop as a community teaching people that arrow functions are the same as regular functions. They have an objective and that's what we need to teach. Knowing how `this` work is important and teaching that when explaining arrow function is important.