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 trialBlessed Marufu
3,927 Pointsarrow function
would kindly assist me to understand this
const greet = 'cool coders' => { `Hi,cool coders !`};
2 Answers
Steven Parker
231,236 PointsThe example shown isn't valid syntax. In particular:
const greet = 'cool coders' => { `Hi,cool coders !`};
^^^^^^^^^^^^^
// this should be a parameter name, not a string in quotes
const greet = 'cool coders' => { `Hi,cool coders !`};
^^^^^^^^^^^^^^^^^^
// this should be one or more complete code statements,
// -or- don't use the brackets
const greet = 'cool coders' => { `Hi,cool coders !`};
^^^^^^^^^^^
// you probably want an interpolation token here,
// as was used in the original version of the function
So, for example, a function that takes a string argument and returns a greeting string that contains it could be defined this way:
const greet = val => `Hi, ${val}!`;
Also, as mentioned in the hint, since arrow functions are not "hoisted", you will need to define the function before the line that calls it.
Blessed Marufu
3,927 Pointsthank you very much
connor ingold
5,382 Pointsconnor ingold
5,382 PointsHere an example of a working arrow function:
However, one thing to be aware of with arrow functions is that if they only have 1 parameter (like the example above) they don't need parentheses. So you can also do this:
And it's still completely fine.