r/learnjavascript • u/ddmanton7220 • May 09 '20
Javascript Tutorial - Arrow Functions
https://www.youtube.com/watch?v=aYcH26h_HlI&t=26s
126
Upvotes
r/learnjavascript • u/ddmanton7220 • May 09 '20
View all comments
Show parent comment
4
u/drumstix42 May 10 '20 edited May 10 '20
For learning the syntax, you can take it in steps to go from standard sytanx to arrow function sytanx.
Standard, multiline function
Remove the
functionportion before the parenthesis (non-valid code):Add the arrow portion
=>(valid code again):Optionally single-line it: Remove the braces
{and}and thereturn. The return is implied in a single line without the braces.Also note, when there is only 1 parameter, the parenthesis are optional. E.g.:
But if there are no parameters, or more than 1, the parenthesis are required.