As you can already see on MDN docs, there are a bunch of advantages and a bunch of things that should get out of strict mode when you are using it properly.
2. Stick to Monomorphism
And the way V8 works isfor example, initially let’s say you are writing this code. What V8 would do in the machine language the machine code itself is, say that we have an argument x and then we need to call the function to get the result. But after optimizing it, V8 could actually see because you’re actually using numbers with this function I’m going to optimize this in a way where I don’t have to call this in JS way. I can just directly call it in the machine code which is you know x86 or whatever.
3. Strict Equality (===)
4. Don’t Pollute Protptypal Chains of Native Data Structure
So similarly anytime you use a library or you do it yourself where you pollute the native prototypal chain of a data structure you actually contribute to the world where we might have restrictions on what features ship to these new prototype chains because thefundamental philosophy of Web is that we don’t try to break the Web. The sites which are working 20 years before should be working now in modern browsers and we cannot do that if we actually pollute the place where the new features have to be added. That is the prototype will change.
So don’t use libraries like MooTools or any other features which actually require you to directly add to (string.prototype.something). Because there are always better ways, better techniques to use. But don’t use these libraries and practices yourself because you’ll probably be contributing in a Web where the Web is rigid and cannot grow.
My 5th and final tip is – always try to use modern syntax over primitive one. The best example for this is async-await over promises, promises over callbacks. Because when you use modern syntax not only do you make your code read and feel much simpler but also help you in performance. We accept that modern features are more performant, better implemented, and much more secured in terms of bugs and stuff.
So Async Await is definitely an example of this. Promises is an example of this over Callbacks. The let and const variable declaration is an example of this. Use strict is also I would put it in modern syntax although it’s not modern syntax, it’s has been alive there for a while. Still, you should use all these modern practices.
So this is it for the Top 5 JavaScirpt Do’s & Don’ts. If you are a JS developer I hope these were helpful!!