Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,636 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,738 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).