20 of my most popular JavaScript Tips 💡

Thread 🧵👇
Pass arguments as an object.

The meaning becomes much more clear from the names of the properties.
Also, the order doesn’t matter anymore.

Trust me - your teammates will be happy 🙌
Extending the standard built-ins is considered bad practice.

Create your own utility class instead 🙌
(...And share it on NPM, if it's useful to others).
Did you know that you can use the Broadcast Channel API to do basic communication between browser tabs, windows, and iframes?

It's pretty simple 🙌
Here's an example of how you can create a reusable and composable pipe using JavaScript.
Use console.trace instead of console.log.
It will show you the complete call stack when debugging.
Understanding closures.

A closure gives a function access to an outer function's scope, even if the inner function is invoked from a completely different context.
The nullish coalescing operator will return its right-hand operand when the left side is null or undefined. Not just falsy.

When working with numbers, this is typically very useful.
Did you know that you can cancel a fetch request using an AbortController?

A common use-case is React:
If a component unmounts while a fetch call is awaited, it can be useful to abort the call.
Instead of using find(), or manually searching a list for an occurrence, use the array method some() instead.

It’s built for exactly that purpose.
TypeScript comes with a utility type, 'ReadonlyArray<T>'.

It's equivalent to 'Array<T>', but with all mutating methods removed.

In this way, you can make sure you don’t change your arrays after creation.
Did you know that you can use object destructuring on arrays?

This is very convenient when we need a group of values from specific indexes.
Did you know that you can trigger a "scroll into view" on a specific element using a single function call in JavaScript?

You can even add a "smooth" behavior to get a nice smooth scroll animation.

Try it for yourself 😎
By using function composition, you can compose functions for different purposes.

In this case, we're using one function to create different "setter" functions for updating state in React.
Use proper variable names - also in callbacks!

Short, concise code is not necessarily an ideal.
Clarity and readability is.

Paying with an extra line is perfectly ok.
Did you know that you can use curly braces with switch-statements?

Takeaways:
🔸 More readable
🔸 Establishes their own block scope
Did you know that you can create your own custom HTML Elements using JavaScript - and then use them in your HTML file just like any other element? 😎

You can create some pretty powerful experiences using this technique.
Did you know - if you add the option -y to npm init, NPM will create a starter setup for you without having to go through all the questions 🙌
You can set timers using console.time.
This can be useful when debugging slow loops or function calls.
3 options you can pass to addEventListener.

{ once: true } can be a lifesaver on some occasions!
Avoid callback hell while using NodeJS builtins.

You don't need promisify either - from NodeJS 10 and up, you can import the promisified versions directly from '[module]/promises' 💪
Did you like these tips? 🤩

Don't forget to like/retweet this thread. Thank you!

Also, you can find all 65+ of these in my FREE e-book 👇
simonhoiberg.com/ebooks/65-code…
Wow, great to see this thread taking off 🤩

If you want to learn how professional teams in the industry wants you to code, be sure to pick up my latest e-book as well 👇

simonhoiberg.com/ebooks/javascr…

• • •

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

Keep Current with Simon Høiberg

Simon Høiberg 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 @SimonHoiberg

7 Dec
Want to start a business?

Keep it simple!
Become a solopreneur and start on your own.

🔸 You can get started almost for free.
🔸 You don't need to quit your regular job.

Here are 5 ideas + strategies you can use to get started 🚀

🧵👇
⚠️ Disclaimer:
You're not gonna be rich overnight.
Building up a business requires hard work.

The good news is - it's probably easier than you think 😉

Keep reading 👇
If you're interested in this topic, be sure to check the video version of this thread as well. I go into much more details here 👇

Read 30 tweets
6 Dec
⚡ I created my first NFT ⚡

It's now for sale 💸

And it's a special NFT as well 👇🧵
I am dedicated to reaching 100K subscribers on YouTube in 2022!

The owner of this NFT will get a 1-minute shoutout in one of my YouTube videos, once I get there!

Let me explain 👇
Do you want to own this NFT?
Then drop an offer here 👇

It is listed for sale until January 1st, 2022 🚀

opensea.io/assets/matic/0…
Read 5 tweets
9 Nov
10 Awesome Developer Tools ⭐️
Start using these in 2021.

🔸 Visual Studio Code
🔸 Postman
🔸 Oh My Zsh
🔸 GitHub Copilot
🔸 GitHub CLI
🔸 GitHub Desktop
🔸 GitHub Actions
🔸 Slack
🔸 Cypress
🔸 CodeSandbox
🔸 Visual Studio Code
code.visualstudio.com
🔸 Postman
postman.com
Read 11 tweets
19 Oct
Are you a content creator?
And are you serious about what you do?

Then take a look at these 5️⃣ creator tools you should start using!

All created by the indie hacker community 😍

👇🧵
1️⃣ Snappify

Awesome tool to create beautiful code snippets.

Made by @dominiksumer and @AnkiCodes.
snappify.io
2️⃣ BrandBird

Create amazing-looking visuals for social media.
Fast and easy 🚀

Made by @d__raptis
brandbird.app
Read 6 tweets
18 Oct
Do you also love JavaScript? 😍

Here are 8 of my best JavaScript Threads.

All collected into one SUPER THREAD
🧵👇
Read 9 tweets
7 Oct
Dealing with rejection 👊

Running a startup comes with a *lot* of rejection.

Here are 5 tips on how to deal with them, and even make them work for you 👇🧵
1️⃣ Don't take it personally.

When you let rejection entail "I'm not good enough", you will start fearing and avoiding it.

Be very careful here.

You can't make a perfect product, and it's crucial for you to get feedback.
Rejection is much more valuable than no feedback at all.
2️⃣ Adopt a curious mindset.

Try your best to not let emotions, cognitive schemas, or other internal mechanisms obscure what a rejection actually means.

It means that your product currently doesn't solve the problem sufficiently.
And that's all.

Now go and work on that 💪
Read 7 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

Too expensive? 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 on Twitter!

:(