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 trialcodingchewie
8,764 PointsCan't this arrow function be shortened further?
In the section on Practice Arrow Functions in JavaScript, under the video Debug Arrow Function Expressions there incorrect code of:
const printDate = date = function() {
console.log(date);
}
is answered with:
const printDate = date => {
console.log(date);
}
but shouldn't it have been shortened/answered as:
const printDate = date => console.log(date)
Curious to know if there is a reason to it not being made into one line?
1 Answer
Mike Tallerico
Full Stack JavaScript Techdegree Graduate 22,892 PointsHey! So I did some research and I found from MDN and some other resources.
You can take the brackets out if it is an expression (3 + x) but if it is a statement you need the brackets. So it is possible they wrote it that way because of that reason. If someone has a better explanation I am curious myself.