JavaScript Functional Programming Tutorial




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”

  1. 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. 😃👍

  2. 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

  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?

  4. 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.

  5. 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

  6. 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]?

  7. 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.

  8. 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.

Leave a Reply