16 JavaScript best practices to improve your code quality

THREAD 🧵:
Before we proceed,

"Programs must be written for people to read, and only incidentally for machines to execute."

—Unknown
{ 1 } Optional Chaining

The optional chaining operator (?.) enables you to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid. Optional Chaining
{ 2 } Data Structure

Carefully consider how you choose your data structures, Access on the left snippet here is ~70% faster than the one on the right because the left one requires no iteration. The right does. Faster Access
{ 3 } Add Dynamic Object Properties

While defining an object, there might be a situation where you need to define the object's properties dynamically.

Let’s look at the example below. Dynamic property
{ 4 } Ternary Operators

The conditional (ternary) operator takes three operands:

1. A condition followed by a question mark ( ? )

2. An expression to execute if the condition is truthy followed by a colon ( : )

3. The expression to execute if the condition is falsy
{ 5 } Destructuring Assignment

This is a clear blessing to keep the code well-formatted. Unpacking objects or arrays is easier than ever before. Destruction
{ 6 } let vs const

Use const even for updating the array, it works as you are not reassigning anything.

Don't use let over const for the array. todolist
{ 7 } Use Template Literals

Strings that we create with double or single quotes have a lot of limitations.

You might want to replace some of your strings with template literals to make working with them a lot easier.
{ 8 } Naming conventions

Take a look are below the examples

JavaScript variables are case-sensitive. Therefore, JavaScript variables with lowercase and uppercase characters are different
Naming Convention Continued ...
{ 9 } findIndex

This is the most underrated feature when it comes to finding a property value from an array of an object.

Use this over normal for loops.
{ 10 } Write Your Own Javascript Contracts and Docstrings

// Adding comments inside a function or using Docstring in the code makes things easier to understand.

Learn more here: jsdoc.app/index.html
{ 11 } Arrow functions

Arrow functions are another very important feature introduced recently to JavaScript. They come bearing many advantages.
{ 12 } Null-ish coalescing

Before introducing the null-ish coalescing operator, we had to use the OR operator || to fall back to a default value if the input was absent.

null coalescing operator ??, offers a better alternative
{ 13 } Make use of shorthand notation(Object Literals)

When designing objects or arrays in JavaScript, line space can be saved by opting for shorthand notation.

This is accomplished by setting the properties or cells of an object or array during declaration rather than after.
{ 14 } Don’t use delete to remove an item from an array

Use splice instead of using delete to delete an item from an array.

Using delete replaces the item with undefined instead of removing it from the array.
{ 15 } Set default values

When creating objects, you can set default values for some or all properties of the object.

Doing so ensures the values of each attribute are not undefined.
{ 16 } Avoid the use of eval() or the Function constructor

Use of eval or the Function constructor are expensive operations as each time they are called script engine must convert source code to executable code.
Thanks for checking this out.

If you liked this thread,

1. Follow @MakadiaHarsh for more such thread for wen development, no-code and personal growth.

2. Retweet the first tweet to help others.

Cheers! 🥂

• • •

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

Keep Current with Harsh Makadia

Harsh Makadia 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 @MakadiaHarsh

14 Dec
It took me 6 months to earn $1800 on the internet.

And then I went from $1800 to $3500 in 5 days 🤯

Here's how you can mint money from your skills.

Passive Income Simplified ↓🧵
With the access to superpower internet, earning from your skill is easier than ever before.

If you use your skills right, you can keep generating passive income while focusing on what matters the most.

Here is my way of earning passive income decoded to help you win ↓
1/ Know your skills

Before building any product or service, take a pen and paper and write down answers to these questions.

- Where do my expertise lie in?

- What skills do I want to learn?

- Can I build an Info product/ eBook on topics that I love the most?
Read 25 tweets
13 Dec
19 days until the end of the year.

Here are 22 lessons to enter in 2022.

THREAD 🧵 ↓
1. There's no dead end

There's always a way out.

So stop worrying right now.

Remember to always see the bigger picture.

A torn page can't ruin the entire book.

A small mistake can't end your BIG BEAUTIFUL life.
2. Start believing in yourself.

Trust your gut.

You're capable of moving hills.

You have immense potential.

You can create miracles.
Read 24 tweets
10 Dec
20K! 🥳

I post content on:
💻Web development
🎖 React
⛔️No-code
📈Personal Growth

To celebrate, I'm giving away 20 copies of my swipe file Twitter Toolkit.

It's everything you need to know about Twitter Growth Strategies.

To participate, just like ♥️ and comment 💬 Image
Here are the winners 🎉

1. @satyam1mishra
2. @therahmanashiq
3. @tonext_level
4. @_gulam_anas_
5. @AmalGhosh3
6. @iamprakash1810
7. @VibaliJoshi
8. @anupama_basrur
9. @hey_Jonuel
10. @panditdhamdhere

Sending copies in your DM soon
Read 4 tweets
9 Dec
Coming up with tweet ideas every day is hard.

But after 6 months of consistency, I cracked the algorithm to keep posting.

Here are 21 ways that will help you generate endless tweets.

THREAD🧵 ↓
When I started my journey I used to sit hours thinking about what to tweet.

Here are all my recipes that I'm using to tweet every single day.

I follow this even today.
1. Document your journey

• Every day you are learning something new.

• You get tons of ideas throughout the day.

• You watch / read / listen to a lot of content.

• Everything you did thought the day is an opportunity to convert into the content.
Read 28 tweets
3 Dec
6.5 years ago I started my web development journey.

If I start from ZERO again I would go with this path:

1. HTML & CSS
2. Git & GitHub
3. Boostrap /Flexbox
4. JavaScript
5. NPM
6. React
7. UI Libraries
8. Styled Components /Tailwind
9. TypeScript
10. GraphQL

THREAD🧵 ↓
1. HTML & CSS

This is the starting step to enter into web development.

Having a good idea about HTML and CSS is a great start to winning the race.

Some people struggle with styling at a later stage in their career, build a strong base instead.
2. Git & GitHub

Why is this step here?

Having a good knowledge of this would help you push all your demo projects to Github.

It will help you build a solid portfolio of projects right from the start.

Learning git is easy and a must, why not start it the right way?
Read 13 tweets
1 Dec
11 Must Use Chrome Extension For Web Developer.

These extensions have boosted my productivity by 5X.

THREAD 🧵 ↓
1. JSON View Pro

A completely free extension to visualize JSON response in awesome Tree and Chart view with great user experience and options.

No advertisements.

Directly beautify JSON from API response in the browser.

chrome.google.com/webstore/detai…
2. LightShot

Lightshot is the fastest way to take a customizable screenshot. Simple interface, nothing useless and lightweight.

chrome.google.com/webstore/detai…
Read 13 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!

:(