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
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.
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:
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.