Just as we can destructure all other objects, we can destructure functions like log() and warn() directly out of the console object.
These are a collection of tips and tricks you can use to improve the performance and readability of your code.
To find the largest value in an array of numbers, we can spread that array into Math.max() instead of manually iterating over it.
Lookup objects can replace long if-else branches and switch statements. We can make them more resilient by checking if a value exists for a given key.
Finding an object with a specific property is slow in large arrays. We can speed this operation up significantly by transforming the array to a lookup object.
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.
By combining regular expressions and parseFloat, we can create a helper function that extracts all float values from a text input.
Syntactic sugar on the Array prototype’s map function and type constructors being functions allow us to quickly map values from one type to another..
The ternary operator can be used at many levels. The further we move it into a statement, the more duplication it can save us.
The String prototype’s replace function only replaces the first occurrence of a substring by default. We can extend that with a global flag on the expression.
By combining map and slice, we can write a helper function to split large arrays into many similarly sized blocks. This is useful for features like pagination.
When the if-branch already returns, we can omit the keyword else. The execution will only go beyond the if-branch if it doesn’t apply anyways.
To improve the readability of React components, we can import the styled-components they use from another file under a ui-namespace.