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 trialMax van den Berge
6,506 PointsIs it necessary to use a semicolon at the end of a Arrow Function Expressions
hi there, i have a question, is it necessary to use a semicolon at the end of a Arrow Function Expressions to run it?
in this video we have been told to use it, because its a variable with a function. but in the examples https://teamtreehouse.com/library/javascript-functions/arrow-functions/concise-arrow-function-syntax and on https://www.w3schools.com/js/js_arrow_function.asp and when i practice, it works also without the ;
thanks for checking my question!
kind regards, Max
const getRandomNumber= x => { const randomNumber = Math.floor( Math.random() * 6 ) + 1; return randomNumber; } document.write (getRandomNumber());
const getRandomNumber= x => { const randomNumber = Math.floor( Math.random() * 6 ) + 1; return randomNumber; };
document.write (getRandomNumber());
1 Answer
Peter Vann
36,427 PointsHi Max!
I'm led to believe they are optional.
These are worth reading (for more info):
http://flaviocopes.com/javascript-automatic-semicolon-insertion/
https://teamtreehouse.com/community/arrow-function-semicolon-required
I hope that helps.
Stay safe and happy coding!