
Modern JS Talk: Arrow Functions
This article was originally published on bmf-tech.com . ※This article is a reprint from the Innovator Japan Engineers’ Blog . What are Arrow Functions? In summary, A new syntax added in ES2015 Shorter than regular function expressions Lexically binds the value of this (making it easier to understand the context of this ) Always anonymous functions The big point of arrow function expressions, written with => , is that they " lexically bind the value of this ". With arrow functions, what used to be written like this... const foo = function () { console . log ( this ); } foo (); Can now be written like this. const foo = () => { console . log ( this ); } foo (); By the way, if there are no arguments, parentheses () are required, and if there is only one argument, parentheses are optional. // Parentheses are required when there are no arguments const foo = () => { console . log ( this ); } foo (); // Parentheses are optional when there is only one argument const foo = ( value ) => { console
Continue reading on Dev.to
Opens in a new tab


