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 Functions Arrow Functions Create an Arrow Function

Holly Groves
Holly Groves
10,175 Points

arrow function

I'm not quite sure what I'm doing wrong here.

script.js
greet('cool coders');

const greet = (name = 'cool coders') => {
  return `Hi, ${name}!`;
};
greet();

1 Answer

Steven Parker
Steven Parker
229,745 Points

With any function declaration, you simply name the parameters. The value for when the function runs is passed by the calling mechanism.

And don't forget what the challenge said, "HINT: Arrow functions are not hoisted". This means that an arrow function must be defined before it is used.

const greet = (name) => {  // only name the parameter here
  return `Hi, ${name}!`;
};

greet('cool coders');      // the value is passed here