JavaScript (original) (raw)
JavaScript is a programming language that started off simply as a mechanism to add logic and interactivity to an otherwise static Netscape browser. In the years since its introduction, it has not only supplanted a variety of other competing languages and technologies to become the standard for browser-based programming, but it has also expanded beyond the client space to become a dominant language on the server side, as well.
What JavaScript can be used for
The Hyper Text Transport Protocol, or HTTP, was designed to do exactly what the name implies, which is to transport HTML text across a network for viewing. But the problem with HTML is that it is completely static, providing no capabilities to implement logic.
Basic features we currently take for granted, such as input validation, autocorrect, progress bars or causing a graphic to change during a mouse rollover, would all be impossible for a browser to perform without some type of scripting capability. As a result, when the web first rose to prominence, every vendor in that space provided some mechanism to make HTML web pages more interactive.
Alternatives to JavaScript
Microsoft promoted a competitor to JavaScript named VBScript, along with plug-in technologies, such as ActiveX Data Object (ADO). Sun Microsystems promoted Java applets that were cross-platform and could be used in any browser.
Many other technologies came and went as the internet matured. In the end, JavaScript won the battle for popularity, and it is the only client-side scripting technology supported by the Chrome, Firefox, Safari and Internet Explorer browsers.
JavaScript is an interpreted language, as opposed to compiled languages, such as C++ and Java. This means that the code written in JavaScript does not go through an intermediary compilation stage in which the source code is transformed into machine language that is easy for a CPU to process.
Instead, JavaScript is interpreted on the fly by the computer processing it. Because JavaScript code is not packaged in a CPU-friendly form, such as Java bytecode or a binary executable, program execution can be slower than a comparable program written in Scala or F#. However, modern JavaScript engines are highly optimized, and inefficiencies are rarely noticeable when using modern hardware.
Short note on JavaScript versus Java
Given the first four letters of the name, a misconception exists that JavaScript and Java are similar. While it is true that Java and JavaScript share some very basic syntax elements, such as the use of semicolons to terminate a statement, the use of curly braces to delineate code block, and similar constructs to create looping and iterative structures, the similarities end there.
The two languages do not originate from the same vendor, the two languages are not maintained by the same consortium, and fundamental language features, such as object orientation and strong typing, are major instances in which the two differ. Java and JavaScript are two very separate and distinct programming languages that should not be confused with one another.
Basics of JavaScript programming
HTML provides a special
Which one will it be?
paper
Modern JavaScript libraries
The basic JavaScript engine that comes packaged with a modern browser only provides a basic and rudimentary set of APIs for software development. To perform complicated tasks, such as implementing an Ajax-based request-response cycle or even performing advanced DOM parsing or string manipulations, a great deal of code needs to be written.
Further complicating the task of writing code to achieve common yet complex programming tasks is the fact that there are differences between each of the major vendors in terms of which versions of JavaScript they implement, as well as how bug-free those implementations are.
To address the differences between browsers while at the same time providing prepackaged code for performing very common tasks, JavaScript libraries have become a mainstay of browser-based UI development. The most popular JavaScript library in use today is jQuery, while competitors such as Prototype and Dojo remain quite popular.
Shortcomings of JavaScript
Two common criticisms of JavaScript is the fact that it is weakly typed and that it is not an object-oriented language. Software developers tend to prefer strongly typed object-oriented languages because these features tend to accelerate software development while also helping to maintain a high degree of software quality.
However, because JavaScript has become the de facto language of internet browsers, being able to write high-quality, bug-free code has become a priority for many members of the software development community.
As a result, new languages, such as TypeScript, have emerged that are both strongly typed and object-oriented. TypeScript looks very much like JavaScript, although it enforces strong typing and provides features for developing in an object-oriented manner. TypeScript is also a compiled language, as opposed to JavaScript, which is interpreted.
However, unlike Java or C++ where the source code is compiled into bytecode or binary, TypeScript compiles into pure JavaScript that can be optimized based on the target browser.
About JavaScript frameworks
A big industry trend in UI design is to push as much logic, processing and state management onto the client as you can and to interact with the server through lightweight RESTful APIs and web services. This has led to the development of full scale JavaScript frameworks that control all the aspects of client-side presentation, often pushing a single-page interface (SPI) user experience.
Popular frameworks in this space are Angular, React and Ember, with these frameworks often leveraging compiled JavaScript languages, such as TypeScript and JavaScript libraries like jQuery for logic and Handlebars.js or Mustache.js for web page templating.