r/reactjs • u/acemarke • Apr 03 '18
Beginner's Thread / Easy Questions (April 2018)
Pretty happy to see these threads getting a lot of comments - we had almost 200 comments in last month's thread! If you didn't get a response there, please ask again here!
Soo... Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch. No question is too simple.
The Reactiflux chat channels on Discord are another great place to ask for help as well.
17
Upvotes
View all comments
Show parent comment
4
u/wasabigeek Apr 26 '18 edited Apr 26 '18
Disclaimer: not an expert
JavaScript lets you pass functions to another function to execute. In the first example you are effectively executing the function and passing only the return value to onClick (I don't remember if alert returns anything, so maybe it's just undefined). What you're doing in the second example is declaring an anonymous function (unnamed function) and passing it to onClick to execute. The arrow function itself isn't affecting this behaviour, you could use a regular function declaration and achieve similar results. Arrow functions are more like shorthand, with the additional benefit of using the parent scope.