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 trialjuami alcazar
6,443 Pointsjust to make sure, the usage of event in the arrow function is just a parameter/argument right? or is it required
const blurHandler = event => { event.target.className = 'highlight'; }
1 Answer
Steven Parker
231,210 PointsThe identifier "event" is a parameter, but it's also necessary in this case because it is used in the handler code.
Arrow functions can also be written without a parameter by placing empty parentheses where the parameter would otherwise go.
const warn = () => { alert("Watch out!"); };
Tom Porter
5,589 PointsTom Porter
5,589 PointsJust in case this is of help to anyone else. This was the first video I'd come across where it used an arrow function without the parentheses around the parameters (here it uses 'event' as a parameter without any parentheses), and I wasn't sure why they were omitted here but previously the standard notation seemed to be:
const exampleVariable = () => { console.log ("example"); };
...I found the page below which confirmed that for arrow notation the parentheses around the parameter are optional when there is exactly one parameter. So you could still use parentheses around 'event' if you wish, or omit. For zero, two or more parameters you must still use parentheses.
https://eslint.org/docs/latest/rules/arrow-parens#:~:text=Arrow%20functions%20can%20omit%20parentheses,of%20parentheses%20in%20arrow%20functions.