By Channaka Jayatilaka

JavaScript is a language where concision is important because JavaScript is downloaded when the page loads. That means that the more concise the JavaScript, the faster the download time. For this reason there are JavaScript Minifiers and Obfuscators that compress the JavaScript files to optimize the download time. If script is compressed, readability is lost and modifying the code will be complicated.

Advantages of JavaScript:

  • Speed. Being client-side, JavaScript is very fast as there are no round trips to the server.
  • Simplicity. JavaScript is relatively simple to learn and implement.
  • Versatility. JavaScript plays nicely with other languages and can be used in a huge variety of applications. JavaScript can be inserted into any web page regardless of the file extension. JavaScript can also be used inside scripts written in other languages such as Perl and PHP.
  • Server Load. Being client-side reduces the demand on the website server.

Disadvantages of JavaScript:

  • Security. Because the code executes on the user’s computer, in some cases it can be exploited for malicious purposes. This is one reason some people choose to disable JavaScript.
  • Reliance on End User. JavaScript is sometimes interpreted differently by different browsers. But server-side scripts will always produce the same output.

Recent JavaScript frameworks help to architect the client side code by providing modular (therefore reusable), cohesive, readable and secure content. jQuery is not a framework, unless developer  do not carefully focus on the code it may ended up in bulks of jQuery spaghetti code.

Advantages of modern frameworks

  • Templating
  • Data-binding
  • routing (single page app)
  • clean, modular, reusable architecture
  • security
  • features for convenience

On the other hand if you organize your code really well, just JavaScript and jQuery can be super powerful. Angular seems to be the framework that everyone loves these days, but it has a steep learning curve.

No matter what one is using I’d follow these principles:

  1. Keep the code in .js files.
  2. Put everything inside an object and out of global scope.

 

This pattern helps to build large applications with a better structure and keep the mess at bay!

Channaka Jayatilaka
Author : Channaka Jayatilaka
Published Date October 31, 2017