These are a collection of tips and tricks you can use to improve the performance and readability of your code.
We sometimes need a type in which only one of two mutually exclusive properties can be set. Setting either property is fine, setting both isn’t.
To asynchronously fetch data in a React component using hooks, we can define and then call an asynchronous function inside of useEffect.
Just as we can destructure all other objects, we can destructure functions like log() and warn() directly out of the console object.
To find the largest value in an array of numbers, we can spread that array into Math.max() instead of manually iterating over it.
There is no “array” type in JavaScript. To check if something is an array, we can use a helper on the Array prototype.
Lookup objects can replace long if-else and switch statements. Checking if a key exists before accessing it makes them more resilient.
Finding an object with a specific property is slow in large arrays. We can speed this operation up 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 into these two blocks.