Loading...

5 JavaScript Do’s and Don’ts You HAVE TO KNOW ?

5 JavaScript Do’s and Don’ts You HAVE TO KNOW ?

1.) Using Strict Mode: Strict Mode is recommended by almost all Javascript Documentations and changes the way the browser views your Javascript Code. A lot of things that are marked as warnings are converted to errors. Enabling strict mode is also not very difficult all you have to do is include the below syntax at the head of your Javascript file.

"use-strict";

2.) Stick to Monomorphism: Let’s take a look at Monomorphism with the help of an example: Suppose you have a function named ‘add’ and you expect two numbers ‘x’ and ‘y’ and return x + y. If the function is being called internally many times, V8 would optimize this function in the machine code if it sees that you are only calling it with two Numbers and would stop calling it in the traditional way and just statically call it in the Machine Code.

3.) Strict Equality (===):  You should always be using Strict Equality in Javascript as there is no use of Double Equality. The only use case of using the Double Equality is when you want to compare a variable with both undefined and null together.

4.) Don’t pollute prototypal chains on native data structures: Don’t use libraries that prototype on top of existing data structures.

5.) Modern Syntax: Always use modern syntax this means using Async/Await over Promises and Promises over Callbacks. This not only helps in readability but also increases performance as well.

 

Sharing is caring

Did you like what Agam singh, Aman Ahmed Siddiqui, Aman Chopra, Aman, Amol Shelke, Anas Khan, Anirudh Panda, Ankur Balwada, Anshul Soni, Arif Shaikh, wrote? Thank them for their work by sharing it on social media.

0/10000

No comments so far