One of the most popular and ubiquitous languages in web development is JavaScript and its popularity seems to be steadily increasing over the course of years. Why is that? What is it about a programming language that originally popped onto the fledgling web development scene in 1995 to handle client-side form validation that has allowed it to continue to stick around and shed some of its toy programming language stigma?
Examination of JavaScript's Popularity
Over time JavaScript has evolved to enable web developers to produce vibrant dynamic web pages. It also comes in a lightweight package taking up little room and producing amazing results. The ability to manipulate HTML content using the Document Object Model (DOM) API is critical to deliver modern results and JavaScript is one language that allows you to do just that. In addition to JavaScript's ability to manipulate the DOM it is also a cross-browser language, which is amazing given the lack of uniformity of DOM browser support. This means that by using JavaScript and its libraries that your code should work similarly across the different browsers.
Another reason for JavaScript's popularity would be due in part to the introduction of AJAX (Asynchronous JavaScript and XML) to the language. This allows a part of a web page to be updated from the server without redrawing the entire page. Originally JavaScript was primarily associated with client-side development, but that is fast changing with the introduction of Node.js within the past handful of years, which allows users to perform backend work with JavaScript that was not possible previously.
Strengths and Weaknesses of JavaScript
Having looked at some of the reasons JavaScript is popular, the next thing to do is to examine some of its strengths and weaknesses as a programming language. After all even when a programming language is popular there will be individuals that will argue for the use of another language versus this one. Each programming language has its strengths and weaknesses, which equates to some languages being better suited to certain tasks.
First up will be an examination of the strengths of JavaScript. One of the primary features of JavaScript is the fact that it uses client side execution for a lot of tasks, which uses the users computer to perform a task versus sending a request to the server and waiting for a response. This does three major things, which are to limit the bandwidth the user has to utilize, the time it takes for an operation to occur, and operations now use the clients processing power versus the servers. At the other end of that spectrum is the use of AJAX, which gets information from the server, but doesn't require the page to redraw once it is received. Another strength of JavaScript is the ever expanding language libraries that are being generated that allow JavaScript to perform some amazing tasks within small packages.
The final very powerful feature that will be discussed in the strengths are JavaScript closures. A closure is created when a function is defined within another function, which allows the closure to access the variables of its enclosing function. This feature is extremely useful, as the closure has access to all of the enclosing functions variables, even after that function is gone. Once a closure is created it will remain in memory until it no longer exists. JavaScript doesn't have formal private object properties unlike Ruby and other languages, but they can be simulated by using closures. This can be accomplished by creating a closure with public access methods for its containing scope.
Now that some of JavaScript's strengths have been discussed, it makes sense to go over some of its weaknesses. One of the major concerns with using JavaScript is related to security, which is related to a powerful, yet controversial, feature that allows a web developer to load JavaScript files that are hosted on a different domain. This is accomplished using the HTML <script>
tag. The problem with this feature is that if the developer does not control the domain that they are loading the JavaScript file from it could be replaced with malicious code, which will then load and run when the web page is loaded.
Another weakness of JavaScript is the varying implementations of the language across browsers. While it is an excellent cross-browser programming language, some of the browsers implement certain features differently, which can result in some unexpected bugs. Certain browsers have been slow to implement certain JavaScript features, so if a developer uses a new feature that is available in Chrome's JavaScript implementation, that same feature might not be available in certain versions of Internet Explorer if at all. When this happens the developer will need to use browser version checking to use certain code with one browser and a different function with another browser. This can add an additional level of complexity to developing with JavaScript.
Closing Thoughts
JavaScript is a fantastic language to develop web applications with from my experience. There is a vibrant developer community with a bevy of open-source libraries that can enhance your page or solve a problem that you're encountering. The introduction of Node.js has allowed JavaScript to transition from a primarily front-end language to a full-stack language with amazing abilities. One fascinating JavaScript library to keep an eye on if you are not already doing so is Meteor, which does several things including live page updates and hot code pushes among many others.
The author of this article seems to think that JavaScript will become the dominant programming language of the enterprise, and while many people did not agree with that sentiment in the comments, I will not be surprised to see this come true in the future.