You make arrow functions perform an implicit return if you follow two rules:
- You write only one line of code in the function
- That line of code is not enclosed in curly braces (
{})
The second rule can be relaxed a little if you want to return an object.
Here’s how you would return an object if you did not use implicit returns.
const functionName = _ => { return { prop: 'value', }}To return objects with an implicit return, you can wrap your object within parenthesis.
const functionName = _ => ({ prop: 'value' })Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson