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 Introducing the Practice

Aaron Thomas
seal-mask
.a{fill-rule:evenodd;}techdegree
Aaron Thomas
Full Stack JavaScript Techdegree Student 13,189 Points

arrow function vs named function

when i use the following i get 'undefined':

function reverseString(string) { [...string].reverse().join('') };

but when i use this it works:

const reverseString = (string) => [...string].reverse().join('');

why is that?

1 Answer

Steven Parker
Steven Parker
231,248 Points

You forgot the "return" in the named function:

function reverseString(string) { return [...string].reverse().join(''); };

The return is implicit in the shorthand form of an arrow function.