Chapter 8. JavaScript Implementations, Syntax Basics, and Variable Types

JavaScript (JS) is a programming language mostly used to produce dynamic and user-interactive webpages. A huge number of websites and all the latest Internet browsers (clients) use and support JavaScript. It is a part of the stack of technologies that every web developer must learn; these include HTML (the content), CSS (the presentation of content), and JS (behavior of the content when a user interacts with the webpage).

Previously, the use of JavaScript was just limited to input validations. For example, it can produce an error message if the user enters invalid information or tries to submit a form with missing information. Now, JS is acknowledged as a fully-fledged programming language that is capable of manipulating with complex calculations and deals with all aspects of a client window. JS enhances the webpage by making it more interactive. For instance, a page with scattered thumbnails can be converted into a pretty stylish image gallery, content of the website can be loaded without forcing the client to reload it over and over, different sorts of error handling can be done in a nice way, user polls can be created and their results can be viewed on a website, and playing with HTML elements on the go and much more is made possible by the power of JavaScript.

JavaScript is quick—real quick. It responds instantly to user actions, such as clicking, double-clicking, resizing, dragging, scrolling, and so on. JavaScript has a syntax that is similar to that of the Java language. The name JavaScript causes confusion for many people. Only the syntax of JS resembles the syntax of the Java language. Otherwise, it has nothing to do with the Java programming language at all.

The following are some of the key differences between Java (programming language) and JS (scripting language):

  • JavaScript is embedded into HTML and runs in a browser, while Java requires a Java Virtual Machine (JVM) for its execution; however, Java applets can run in browsers.
  • JavaScript is known as a client-side language as it runs in the browser on the client end, but now, Node.js is the gateway of JS to the server end. On the other hand, Java runs on the web server, for example, Apache Tomcat.
  • JavaScript is usually interpreted by the client, while Java is compiled and then executed by a JVM.
  • JavaScript was created by Netscape (now Mozilla) while Java was developed by Sun Microsystems (now Oracle).

History of JavaScript

Brendan Eich of Netscape (now Mozilla) developed JavaScript in 1995. Originally, it was named as Mocha, later its name was changed to Livescript, and finally it was renamed to JavaScript. After its launch, Microsoft introduced Jscript—their own version of JavaScript that was included in Internet Explorer. Netscape submitted JavaScript to European Computer Manufacturers Association(ECMA) for standardization and specification. The standardized version was named ECMAScript. ECMAScript is a trademarked scripting language specification standardized by ECMA International.

The ECMAScript V5 introduced a new mode called the strict mode; this brought forward better and thorough error checking to avoid constructs that cause errors. Many ambiguities from the third version were removed and real-world implementations were added.

The ECMAScriptV6 added plenty of new syntax for writing complex programs. It introduced classes and modules extending the semantics from V5. Iterators were also added in this version along with many Python-styled semantics, including proxies, arrow functions, generators and generator expressions, maps, sets, and so on.

Evolution of JavaScript

After the standardization of JavaScript as ECMAScript, the next step was to have complete control over Document Object Model (DOM).

The HTML is parsed into DOM by the web browser's DOM API. DOM is the client understanding of the webpage. All the elements/nodes are converted into a tree-like structure known as DOM Tree. The members of this tree can be manipulated on the fly using different methods such as getElementById() and getElementsByName(). The HTML source we see in developer tools, such as Inspect Element, Fire Bug, and so on are DOM View. These development tools also help a lot to modify our DOM instantly.

Later, Asynchronous JavaScript and XML (AJAX) was introduced to make asynchronous applications. The data was sent to and received from the web server without reloading or refreshing the whole DOM Tree (asynchronously).

As JavaScript advanced, different JS libraries were developed to ease DOM manipulation. Some of the popular libraries are jQuery, Prototype, and Mootools. The primary feature of these libraries is to handle DOM manipulations, animations, and AJAX. The most famous and widely used JS library is jQuery. Furthermore, a server-side version of JavaScript was developed and named Node.js.

In this book, you will learn about JavaScript, its history, and its evolution. You will learn about its implementations and syntax. Function references and complete examples for how to use it in different cases are also provided.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.120.136