JavaScript Best Practices- Part 4

Blog >> Javascript Best Practices >> JavaScript Best Practices- Part 4

1. Self-Executing Functions

Rather than calling a function, it’s rather simple to create a function run automatically when a page loads, or a parent function is titled. Basically wrap your functions in addition, and then add an further set, which fundamentally calls the function.

2. Raw JavaScript Can Always Be Quicker Than Using a Library

JavaScript Archives, such as JQuery and Mootools, can save you a vast amount of time period when coding – specifically with AJAX actions. Having said that, continuously preserve in mind that a library cannot ever be as fast as raw JavaScript.

JQuery “each” technique is abundant for looping, but using a natural “for” statement will continuously be an ounce faster.

In this segment, we enclosed the best practices for identifying variables, mentioning, and gave a few guidelines to help you establish your code.

3. Remove “Language”

Since, it was not exceptional to find the “language” feature within script tags.

4. Never Declare Number, String, or Boolean Objects.

All the time give numbers, strings or Booleans as aboriginal standards. Not as substances. Announcing these categories as substances, slows down performance speed, and produces horrible side effects.


5. Don’t Use new Object ()

  • Use {}instead of new Object()
  • Use “”instead of new String()
  • Use 0instead of new Number()
  • Use falseinstead of new Boolean()
  • Use []instead of new Array()
  • Use /()/instead of new RegExp()
  • Use function (){}instead of new Function()