Splitting arrays into X elements and “the rest”
When a feature calls for the first five photos from a list and a link that says “27 more photos”, we can split the list of photos into these two blocks.
Read fire tipIf a JavaScript arrow function immediately returns a value, writing return
is optional (if we also remove the curly brackets). The return
is then implied, making it an “implicit return”.
// we could write the `return` explicitly
const getPumpedAbout = thing => {
return `Pumped about ${thing}!`
}
// if we write it like this, the `return` is implied
const getPumpedAbout = thing => `Pumped about ${thing}!`
// there is no difference in how we would call these functions
getPumpedAbout('implicit returns') // ⇒ 'Pumped about implicit returns!'
When a feature calls for the first five photos from a list and a link that says “27 more photos”, we can split the list of photos into these two blocks.
Read fire tip