When exploring the documentation for the fat arrow syntax, you will come across various examples such as:
arg => console.log(arg); // <-- () not necessary for single argument
(a, b) => console.log(a,b); // <-- () required for multiple arguments
arg => { return arg; } // <-- includes a return statement within {}
(a, b) => { return a+b; } // <-- includes a return statement within {}
this.dropDownFilter = values => values.filter(option => option.value !== 'Others')
One key advantage is that it inherently incorporates lexical this. Therefore, there is no need to store this
in a variable to utilize it within the function.
This can be likened to:
this.dropDownFilter = function(values) {
return values.filter(function(option) {
return option.value !== 'Others'
})
}
If we analyze further:
- The assignment of an anonymous function with the argument
values
to this.dropDownFilter
.
- The fat arrow syntax features an implicit return statement.
- The inner
.filter()
method contains an anonymous function responsible for returning the filtered value.