DEV Community

loading...
Cover image for 4 Tips for JavaScript 2021 to write optimized code

4 Tips for JavaScript 2021 to write optimized code

animeshdhanuk profile image Animesh Dhanuk ・2 min read

tips for JavaScript 2021 to write optimized code

JavaScript is the front-hand language as we know. JavaScript is using for web designing, mobile apps, game development, crate web servers, and JavaScript is WebSite Scripting Language(WSSL). That's one of the most used languages by developers, programmers, and coders.

1. Use Logical Assignment Operators

Now, In JavaScript 2021 logical operators and assignment operators are combined, so you can use both in the same syntax as below. And That's one of the most used tips for JavaScript 2021 to write optimized code.

OR Operator

The logical OR assignment (X ||= Y) operator only assigns if X is false.

AND Operator

The logical AND assignment (X &&= Y) operator only assigns if X is true.

2. Use Numeric Separators

This is one of the most used operators by developers and programmers when they have a large amount of numbers. When using a separator in number it looks better than an unseparated number. This is one of the best tips for JavaScript 2021 to write optimized code.

3. Use Replace All

The replaceAll() method returns a new string with all matches. It returns any pattern that can be a string. The original string is left unchanged. The syntax of this operator is replaceAll(regexp, newSubstr). That's one of the most used tips for JavaScript 2021 to write optimized code.

4. Use Promise.Any()

The promise.any() method is to resolve your promise() as soon as which is passed by you. If no promise is passed then it returns promise is rejected with an error. That's one of the best tips for JavaScript 2021 to write optimized code.

I Hope You Enjoy The Above Tips. Thank For Reading...

Read More

Discussion (9)

Collapse
Sloan, the sloth mascot
Comment deleted
Collapse
hasnaindev profile image
Muhammad Hasnain • Edited

Have you considered that perhaps he is a complete newbie trying to learn things, write them in his own words and share them so he can solidify those concepts? Please, either be kind and give good advice or keep shut.

Collapse
hasnaindev profile image
Muhammad Hasnain • Edited

I wasn't wrong after all. The Software Engineering industry is indeed toxic. To all the "senior" developers, dev.to community is beautiful and most of it comprises of newbie coders who come here not only to learn, but to also share what they learn to solidify whatever concepts they learn.

So, instead of being an a**ho*e, give good advice and guidance, otherwise I don't really know what you are doing on this forum.

Collapse
codefinity profile image
Manav Misra

Glad you put "senior" in quotes. That's some title that recruiters and companies have created for categorizing folks. Anyone can assume pretty much whenever they want. It's basically meaningless.

It's not like being a professional engineer, medical doctor or even a certified HVAC tech.

Collapse
larsonnn profile image
Lars Feldeisen

What is the "optimization" here?

Collapse
lukaszahradnik profile image
Lukáš Zahradník • Edited

Don't do the 1. "tip" please

Collapse
ajanibilby profile image
Ajani James Bilby

I mean some of these tips do have possible slight performance increases if you do think about it.
1) One less name resolution
2) I mean optimising readability is a type of optimisation
3) IDK about this one, but it is certainly possible some JavaScript implementations could optimise this case more than a precompiled regex statement
4) Using a native function for promise any rather than a self implemented one would certainly be more performant.

All of that being said, these performance increases and optimisations are almost negligible in comparison to some other factors. But that doesn't change the fact they are true, and IDK why this author seems to be getting some hate for it

Collapse
endershadow8 profile image
EnderShadow8

These are some good tips, it's just "optimisation" is definitely the wrong word here. I would say these are more "code maintainability" tips.

Some comments have been hidden by the post's author - find out more

Forem Open with the Forem app