Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Is there a JavaScript functional programming course as I notice there is one for Java?

Here is the link to the Java functional programming course(https://teamtreehouse.com/library/introduction-to-functional-programming), I was hoping there was one for JavaScript but can't find it.

4 Answers

Emmanuel C
Emmanuel C
10,635 Points

I doubt there would be one, since technically JavaScript is always in the style of functional programming. Even when you create classes and objects in JS, its just a fancy compiler illusion as it all turns into functions calling other functions behind the scene. Its part of the reason why when declaring a function in old school JS, you actually have to use the keyword function.

I am building a calculator and I have the below array outside of the function and then the function mutates it, which I understand is poor coding practise.

How would I incorporate the array into the function, keep in mind there will be other functions (plus, minus etc) which also need to access the array and updated data within it.

let arr = []; // Store user input.
let str = ''; // Display user input in the display section.

decimal.addEventListener('click', () => {
  arr.push('.');
  str = str.concat('.');
  display.value = str;
});

There is one course and one workshop related to functional stuff.. but Not exactly the same as Java,

https://teamtreehouse.com/library/understanding-closures-in-javascript

https://teamtreehouse.com/library/callback-functions-in-javascript

I agree with Emmanuel

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,696 Points

The closest equivalent to that Java course in the Treehouse library I think would be this one: JavaScript Array Iteration Methods. You don't have to call .stream() as you do in Java, but it's the same basic idea (map, filter, reduce).