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 trialAdam N
70,280 PointsVideo seems to imply that this should work
At ~0:36
const hi = x => { x }
console.log(hi(5)) //undefined
1 Answer
andren
28,558 PointsYeah that bit in the video is a bit misleading. It seems to suggest that as long as there is only one line of code you can omit the return
keyword, and also omit the braces if you want to. But in reality you actually need to omit the braces around the code, that is what marks the code as a concise arrow function.
In other words:
// Valid concise arrow function
const hi = x => x
// Invalid concise arrow function
const hi = x => { x }
So if you simply remove the braces in your code like this:
const hi = x => x
console.log(hi(5))
Then it will run fine.