Oliver Jumpertz Profile picture
Jun 7, 2021 โ€ข 17 tweets โ€ข 5 min read โ€ข Read on X
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! ๐Ÿ’›๐Ÿ™๐Ÿผ

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Oliver Jumpertz

Oliver Jumpertz Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @oliverjumpertz

Sep 20, 2023
If you're using AWS Lambda, stop scrolling and find out how you can potentially save a few to a few thousand dollars a month.

I actually saved my employer 8k dollars a month from only two Lambda@Edge functions running for each CloudFront request:
Did you know that whenever you deploy a Lamda function to AWS, it automatically tries to create a log group for you and automatically starts to send even only access logs through that pipe?
Even if you don't have a single log statement within your Lambda function, the Lambda runtime will write access logs to CloudWatch.

AWS will happily bill you for that without you probably noticing, especially if you don't intentionally log anything.
Read 8 tweets
Feb 21, 2023
Git is by far the most used source control management tool out there.

It is basially an essential to know. And this justifies knowing a few of the most important git commands you need in your daily work.

Here are 19 that any developer should know: 19 essential git commands for every developer.
1. Initialize a repository

git init is the most basic command.

It initializes a new repository in your current folder and starts the version control flow for your repository. git init
2. Clone a remote repository

You don't necessarily need to create a new repository.

Sometimes you just want to download an existing repository and contribute to it.

This is where git clone comes in. git clone <remoteUrl/>
Read 21 tweets
Feb 20, 2023
I've seen some people complaining about Twitter putting text-based 2FA behind the paywall.

There is gladly a far better way that still works for everyone (and to be honest, text-based 2FA is flawed).

A small tutorial:
Go to "Settings and Support". .
Now lick on "Settings and privacy". .
Read 13 tweets
Feb 9, 2023
If you learn Rust, you'll learn much more about computers and optimization/programming than many other programming languages can even teach you.

Want an example?

The Rust compiler can optimize away the discriminant of an enum by using invalid bit patterns for fields. โ†“
Consider this scenario:

enum GlassState {
Filled(u8, bool)
Empty
}

And let's now simplify how that "looks" in memory:

Filled(69, true) => [69, 1]
Filled(69, false) => [69, 0]

And what about Empty?

Well... -> Empty => [0, 2]
What happened here?

The first value is irrelevant.

An Empty does not have the same u8 as the variant Filled has.

You can put anything in the first place; it will never get read but still takes up space.

The second value, however, is an invalid bit pattern for a boolean.
Read 5 tweets
Jan 23, 2023
The hardest part of being a senior software engineer:

Having experience.

Sometimes, experience tells us to take care of a million things that might not even be relevant to the case at hand.

Sometimes, experience hinders you from iterating fast.
It may sound counterintuitive, but it can really be a problem.

"What if this happens?"

"We once had this case where X happened; we need to guard against that!"

"We should probably add X and Y, so we don't run into Z..."
Often, objections like these are valid, but also, often, they are not because you want to gather data to see what's really relevant.

A prototype does not need an extended set of safety guarantees if deployed in a completely new scenario.
Read 6 tweets
Jan 20, 2023
Algorithms in Rust:

This is the infamous fast inverse square root implemented in Rust.

This particular implementation was initially discovered in Quake III Arena's source code and rose to fame in 2002 and 2003.

Oh, and it shows some pretty interesting traits: const THREE_HALFS: f32 = 1.5; const WTF: u32 = 0x5f3759df;
As the graphic already states, the inverse square root is often used in computer graphics.

It is used to calculate reflections of lighting and shading, when normalizing corresponding vectors.
In 1998 and 1999, computing power was far away from the levels we have today, and this often required some clever use of maths or algorithmics to make things fast enough, especially in games and graphics.
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(