Understanding JavaScript Implementation: A Note-Based Article
This article is based on notes I made while reading "Professional JavaScript for Web Developers" by Matt Frisbie.
Introduction
JavaScript is a programming language widely used in web development, extending far beyond the browser. This article breaks down JavaScript's core components and evolution based on its ECMAScript standards, host environments, and how it interacts with web pages and browsers.
JavaScript vs. ECMAScript: Understanding the Difference
JavaScript and ECMAScript are terms often used interchangeably, but they are different. ECMAScript, defined by the ECMA-262 standard, outlines the core language that JavaScript is built upon. JavaScript, however, includes additional features specific to web development and host environments, making it more than just ECMAScript.
Components of JavaScript Implementation
JavaScript implementation consists of three distinct parts:
The Core (ECMAScript)
The Document Object Model (DOM)
The Browser Object Model (BOM)
Each part serves a unique purpose, enhancing JavaScript’s flexibility and utility in different environments.
1. The Core (ECMAScript)
ECMAScript, defined in ECMA-262, is the foundation of JavaScript. It can be used in environments other than web browsers. ECMAScript serves as a core language that different host environments, like web browsers and Node.js, can build upon by adding their own extensions.
Host environments provide an ECMAScript implementation with specific APIs for interacting with the environment. For example, web browsers use ECMAScript’s types and syntax, extended with the DOM API for manipulating HTML documents.
Core Language Components in ECMA-262
The ECMA-262 specification outlines basic language features:
Syntax
Types
Statements
Keywords
Reserved Words
Operators
Global Objects
These components establish the foundation for JavaScript by defining syntax and semantics, allowing JavaScript to work consistently across different platforms.
ECMAScript Editions: Evolution of the Standard
ECMAScript has evolved through several editions, each introducing new features and improvements to meet web development needs.
First Edition
The first edition, ECMA-262, standardized Netscape’s JavaScript 1.1 but removed browser-specific code and required Unicode support for multiple languages. Early JavaScript versions (1.1 and 1.2) did not fully conform to this standard.
Second Edition
This update primarily aligned ECMA-262 with the ISO/IEC (International Organization for Standardization / International Electrotechnical Commission)-16262 standards. It involved editorial changes but did not add or remove any features.
Third Edition
The third edition transformed ECMAScript into a stronger programming language by adding support for regular expressions, new control statements, try-catch
error handling, and key updates for internationalization.
Fourth Edition
The fourth edition aimed to add many new features, like strongly typed variables and new data structures. However, it was considered too complicated and was dropped in favor of smaller updates.
Fifth Edition
The fifth edition introduced “strict mode,” native JSON support, and methods for inheritance, enhancing JavaScript’s capabilities for complex applications.
Sixth Edition (ES6/ES2015)
Released in 2015, ES6 introduced major improvements like classes, modules, arrow functions, promises, and new data types. This version was a turning point for JavaScript, allowing for more powerful and organized code.
Seventh Edition (ES7/ES2016)
Released in 2016, ES7 introduced smaller features like Array.prototype.includes
and the exponentiation operator.
Eighth Edition (ES8/ES2017)
In 2017, ES8 included asynchronous functions, rest and spread properties, and new regular expression features.
Ninth Edition
The ninth edition includes features in "stage 3" development, including dynamic imports for ES6 modules.
ECMAScript Conformance
For a JavaScript implementation to be ECMAScript-compliant, it must support all types, values, objects, properties, functions, and syntax outlined in the standard, as well as the Unicode character set.
2. The Document Object Model (DOM)
The DOM is an API designed to interact with HTML and XML documents. It maps each component of a webpage into a hierarchy of nodes, allowing developers to modify content and structure dynamically.
For example, the following HTML structure:
<html>
<head>
<title>Sample Page</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
can be represented in a tree-like structure using the DOM, giving developers control over document content through DOM methods. This flexibility is essential for creating dynamic, interactive web pages.
3. The Browser Object Model (BOM)
The Browser Object Model (BOM) lets JavaScript interact with the browser itself, not just the webpage content. Originally, BOM features weren't standardized, so they worked differently in each browser. However, HTML5 introduced a standard for many BOM features, making them work the same way across all browsers.
The BOM provides tools for:
Managing browser windows (opening, closing, resizing)
Accessing information about the browser (
navigator
), the screen (screen
), the current page (location
), and browser performance (performance
)Handling cookies
Using objects like
XMLHttpRequest
for network requests
Because each browser historically implemented BOM features differently, cross-browser compatibility was challenging. HTML5 addressed this by establishing in practice standards.
Conclusion
JavaScript’s implementation includes ECMAScript, the DOM, and the BOM, each contributing to its role as a core technology in web development. Understanding these components and the evolution of ECMAScript editions helps developers leverage JavaScript’s full capabilities, from browser scripting to server-side applications.