14 What is JavaScript?
JavaScript is a fully-functional programming language that was designed to embed computer programs into an HTML page to create Dynamic HTML (DHTML). It was first shipped with the now-defunct Netscape browser in 1995. Dynamic HTML pages make use of JavaScript statements and functions to change their appearance and contents both as they are loading and after they are loaded, in response to user interactions and other events. Static HTML pages, on the other hand, always look the same and do not change once they are loaded. Static pages used to be the only thing on the web, but they are now all but extinct.
Almost all web applications make use of JavaScript for drop down menus, pop-up windows, slide shows, image magnifiers, instant form feedback, and other dynamic elements that can be implemented on the client side. Most web sites also make use of JavaScript’s AJAX APIs to load new content from the server and refresh parts of the page after load time. This is how Google makes suggestions as you type into the search bar, and how social media sites load new content when you get to the bottom of your activity feed, creating an endless scroll. In both cases, JavaScript functions fetch new content from the server in response to your actions and then format and display it on the page for you.
Two Popular Misconceptions
There are two widely-held misconceptions about JavaScript. The first is that Java and JavaScript are the same language, or two versions of the same language. In fact, JavaScript is a very different programming language from Java. The similarity in names is the result of a marketing decision made by Netscape in the 1990’s. It’s true that the two languages can look similar at first glance. Like Java, JavaScript derives much of its basic syntax from the C programming language. But don’t be fooled by surface appearances. JavaScript’s variables, arrays, objects, and functions are implemented very differently from their counterparts in Java, and actually share more in common with languages like Python.
The second misconception is that JavaScript is somehow a less powerful, simple, or “lightweight” language than languages like Python, Java, and C. In this case, there are several kernels of truth. It is true that JavaScript on the client side runs in a restricted environment and that historically, JavaScript has been used mostly for very simple tasks. It is also true that JavaScript runs more slowly than languages like Java and C (it’s interpreted rather than compiled), and client-side JavaScript programmers do not have easy access to the same kind of standard plugin libraries that Java and Python programmers enjoy.
But JavaScript is not “lightweight” or “simpler” in the sense of being easier to learn. Writing effective code in JavaScript can be just as difficult as any other language, and a deep understanding of how the language works is as important to being an effective JavaScript programmer as it is for a programmer in any other language.
JavaScript is also not “less powerful” in the theoretical sense than any other language. JavaScript is a fully developed, Turing complete, programming language. This means that there is no computational problem that can be solved in any other programming language that could not also be solved in JavaScript.
The Dominance of JavaScript
With the release of HTML5, JavaScript became the language of choice for web apps, hybrid apps, and even many standalone mobile apps. With the demise of Adobe’s Flash, JavaScript also become a primary way to produce graphics-intensive web content like games, interactive diagrams and fancy menu systems. And with the release of Node.js, JavaScript can now also be used to write code on the server side of a web app. At this point, a solid working knowledge of JavaScript is a requirement for many programming jobs.
By at least one measure, JavaScript might be the most frequently used programming language: If you counted up all the lines of JavaScript in the browser caches of all the computers in the world, the total would probably be higher than the number of lines of source code in any other language.