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 JavaScript and the DOM (Retiring) Getting a Handle on the DOM A Simple Example

Mark Plattner
Mark Plattner
2,082 Points

What's the story with () => ?

What is going on here with ",() => {}"

myButton.addEventListener('click', () => { myHeading.style.color = myTextInput.value; })

This wasn't covered in Intro to JS and I know => is not an operator? So the whole syntax is confusing to me. Can you please explain it?

Michael Caveney
Michael Caveney
50,144 Points

It's an Arrow function, part of ES6 JS, those are talked about in the ES6 course, and there's a workshop on them here: https://teamtreehouse.com/library/introducing-arrow-function-syntax

4 Answers

Yeah, Michael Caveney hit the nail on the head! :) It's the ES6 way of writing function() {...}. There's a few other benefits we're getting from writing function expressions as arrow functions, which that introduction to arrow function syntax course covers. :D