Oliver Jumpertz Profile picture
The Educated Software Engineer | Writing over @ https://t.co/EVIvqJCm8q | YouTube @ https://t.co/Wucct0uW1H

Jun 7, 2021, 17 tweets

Here is a collection of visual JavaScript tips and explanations that can help JavaScript developers of any skill level!

๐Ÿงต๐Ÿ‘‡๐Ÿป

The anatomy of a for-loop in JavaScript. ๐Ÿ‘‡๐Ÿป

The anatomy of a while-loop in JavaScript. ๐Ÿ‘‡๐Ÿป

The anatomy of a do-while-loop in JavaScript. ๐Ÿ‘‡๐Ÿป

The anatomy of a for-of-loop in JavaScript. ๐Ÿ‘‡๐Ÿป

The anatomy of Array map in JavaScript. ๐Ÿ‘‡๐Ÿป

This is how you can combine a Promise and setTimeout to create a cancelable delay. ๐Ÿ‘‡๐Ÿป

This is how you can make an argument required by using a function as a default parameter.

Whenever no argument is passed, the function fires and throws an Error that tells what went wrong. ๐Ÿ‘‡๐Ÿป

The Performance API is actually way better suited to measure execution times than the Date API.

Please be informed that many browsers reduce the precision to prevent fingerprinting.

It's best to use it in your tests ran with Node! ๐Ÿ‘‡๐Ÿป

You can unpack all nested arrays of an array by passing Infinity as an argument to Array flat.

This way, you get all individual values one after the other. ๐Ÿ‘‡๐Ÿป

The nullish coalescing operator is often a better choice than using the logical OR operator.

Contrary to the logical OR, the nullish coalescing operator only reacts to null and undefined. ๐Ÿ‘‡๐Ÿป

A destructuring assignment can save you a few lines of code, especially when you want to unpack multiple nested properties of an object. ๐Ÿ‘‡๐Ÿป

You can usually not destructure into existing variables.

But by putting parentheses around the statement, you actually can! ๐Ÿ‘‡๐Ÿป

You can also destructure arrays and extract individual values, as well as the remaining rest.

This is often more readable than accessing individual entries of the array. ๐Ÿ‘‡๐Ÿป

You can get the last items of an array by using slice with a negative number.

This returns an array with the number of items you specified with the respective negative number in the order they are placed in the original array. ๐Ÿ‘‡๐Ÿป

You can format the output of JSON.stringify by passing an indentation string as the third argument of the function. ๐Ÿ‘‡๐Ÿป

And that's it for now.

I hope you found something useful for you! ๐Ÿ’›๐Ÿ™๐Ÿผ

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.

Keep scrolling