Linters and strict mode

There are some other bad parts in JavaScript that could cause performance issues on some occasions. In order to keep an eye on all of these bad parts and replace them with JavaScript’s good parts, it is highly recommended that you use a tool that will allow you to find issues with a piece of code even before you run it for the first time. These tools are linters.

JSLint, ESLint, and Prettier are tools that can help you find sloppy code and fix it, even automatically in some cases. Some linters, such as ESLint, might even help you improve your code by reducing the number of statements, reducing the nesting of structures by replacing them with functions and Promises, identifying cyclomatic complexity—which is measuring the number of branches a single piece of structural code has—and maybe allowing you to replace those structural pieces of code with more functional ones, as we will see in the next chapter. You can find these tools at the following addresses:

An added benefit of using linters is the fact that they make JavaScript code compatible with ES5's strict mode. Whenever possible, strict mode should be used. It is as easy as adding a use strict; statement at the beginning of a script or a function in order to use it. Amongst the many benefits of using strict mode is a simplified mapping of variable names to variable definitions (optimized namespace lookups), prohibition of the with statement, prevention of unexpected introduction of variables into the current scope through the use of eval statements, protection against "boxing" (forced instantiation) of the this variable when it is not containing an object and it is passed to a function, which reduces performance cost considerably, and the removal of most performance preclusions, such as accessing the function caller’s variables and "walking" the JavaScript stack at runtime.

Many excellent books and videos on JavaScript performance have been published by Packt Publishing and I highly recommend that you read them in order to master all these fine tools.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset