11 JavaScript Tricks for you to write 57% more elegant code! ๐๐๐
๐ Follow Thread ๐งต
1. Easily swap variables by using destructuring.
2. Transform number to string or string to number faster with +
3. Easily remove duplicates from an Array with a new Set and destructuring!`
4. You can make an array shorter or empty by overriding a built-in method called length by assigning a smaller number to it.
5. Use Array.from with arrow function to quickly generate an array of numbers: from 0 or 1 to whatever you want!
6. Get a random number in a specific range.
It can be useful when we want to generate some data for testing purposes or for a JavaScript game.
7. Quickly transform your Array of strings to an Array of numbers with map method and Number.
8. Use reduce method to calculate the sum of all array elements.
9. Convert values to booleans with Bang-Bang operator - โ!!โ
10. Easily merge multiple objects into one with object destructuring!
11. Simplify your code with optional chaining! It really helps to make your code more readable and elegant.
That's all folks! ๐ฅ๐งฏ
If you found this thread useful, please consider following @eugZolotarenko and retweeting the first tweet. ๐ข
Go to the top of the Tweet! ๐
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.
