One of a programmer's favorite things to do is to write clean and concise code. Arrow Functions
are a new way to write functions, given to us by the ECMAScript 6 (The software standard JavaScript is based upon) update of JavaScript.
It's a little different from regular functions, take a look:
// ES5 Function
function addNum(num1, num2) {
return num1 + num2;
}
// Arrow Function (stored in variable)
const addNum = (num1, num2) => {
return num1 + num2;
};
If you've done some research, you may come to the following conclusions:
- First of all, the Arrow Function is anonymous by design. If we want to refer to it, we should store it into a variable.
- Secondly, the way Arrow Functions can be written can differ (while still working the same way). Sometimes you don't need the
()
if there's a single parameter. Sometimes you canreturn
a value without use for thereturn
keyword.