Oliver Jumpertz

Oliver Jumpertz



I post a lot of visual JavaScript tips, explanations, and algorithm implementations every day. 💛 Here is a collection of them. 📖 They will definitely help developers of any skill level to learn something new. A thread. ↓

1. The Destructuring Assignment A destructuring assignment is a well-readable way to extract multiple properties from an object at once. It can save you a few or even many lines of code. ↓

2. Destructuring From A Possibly Undefined Property You can't destructure from a nested, undefined object; it leads to a TypeError. You also can't use optional chaining at the end. If you combine destructuring with the nullish coalescing operator, though, it works. ↓

3. Make Arguments Required By Using Default Parameters You can use default parameters to make function arguments required. Just use a function as a default value that throws an Error if the parameter is not supplied. ↓

4. Use Array.findIndex When Dealing With Objects indexOf uses strict equality comparison under the hood. This means it can only ever find the exact reference but not an identical object. 'findIndex' fixes this because you can pass a callback to identify an object. ↓

5. Destructure Function Parameters To Increase Readability For Users Destructuring your function's parameters can drastically increase the readability and usability of your functions. By putting curly braces around your arguments, you work with individual arguments. ↓

6. Destructure An Object Into Existing Variables You can destructure an object into existing variables by enclosing the expression in parentheses. Otherwise, the runtime assumes a code block and throws an Error. ↓

7. Use Numeric Separators To Keep Large Numbers Readable You can use numeric separators to create readable groups for large numbers. No more guessing or analyzing what number you actually see there. ↓

8. The Nullish Coalescing Operator The nullish coalescing operator only reacts to null or undefined, while the logical OR reacts to all falsy values, including "", 0, false, etc. When you want to ensure you only catch null and undefined, this is your way to go. ↓

9. Promise .race vs Promise .any You don't always need Promise all. race and any are valid alternatives for their individual use cases. race waits for the first Promise to settle somehow, even if it rejects. any tries to get the first successful Promise. ↓

10. Anatomy Of Array .map This is the anatomy of array's 'map' method. You use 'map' to convert all elements of an array into other values, e.g., converting numbers to strings, adding a specific number to each element, etc. ↓

11. The Exponentiation Operator The exponentiation operator is a recent addition to JavaScript. It's a replacement for Math .pow(), and can be easier to read than a function call. ↓

12. Reverse An Integer Reversing an integer is a pretty interesting task. An easy way would be to convert the int into a string, reverse that string, and then parse it again as an integer, but there is another way. ↓

13. Array .copyWithin copyWithin is a lesser-used method of arrays, but still an interesting one because it's a high-performance implementation for in-place copying. Handy for sorting algorithms or to delete elements in place. ↓

14. Merging Multiple Objects You can merge multiple objects by spreading them into a new one. The properties are copied over in the order of the objects. If an object that comes later has the same properties as a previous one, the new ones overwrite the old ones. ↓

15. Proxies Proxies are objects that wrap other objects and behave and act like them. The interesting thing is that you can inject additional behavior with the Proxy. ↓

16. The Void Operator The void operator turns anything into undefined. It's not used that often nowadays, but still useful, especially when you want to ensure that something never returns anything. ↓

17. Fisher-Yates Shuffle The Fisher-Yates shuffle is an algorithm to shuffle arrays and lists. It is unique because it has an equal chance for all permutations to happen. Means: It's fair and unbiased. ↓

18. Linear Search Linear search is the simplest search algorithm. It iterates an iterable from start to end and tries to find one or multiple results. No tricks involved. This is one possible implementation. ↓

19. The Primality Test The primality test checks whether a number is a prime number. There are more effective tests for huge numbers, but this works well on a smaller scale. ↓

20. Basic Fast Deep Clone You can use JSON parse and stringify to deep clone objects. It does, however, not work for more complex nested properties, but it's one of the fastest alternatives to use if your objects don't contain those. ↓

21. Thread end That's it for this thread. I hope you learned something valuable. If you enjoyed reading this thread, consider dropping a like, retweet the first tweet, and follow me (@oliverjumpertz) for more content like this.

Follow us on Twitter

to be informed of the latest developments and updates!

You can easily use to @tivitikothread bot for create more readable thread!
Donate 💲

You can keep this app free of charge by supporting 😊

for server charges...