liveBook · Manning

Chapter 5: Vanilla JavaScript

What you will learn in chapter 5 of Vanilla Web

Introduces Vanilla JavaScript’s role in web apps and explains why ECMAScript versioning matters when code is shipped without a framework build process.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces Vanilla JavaScript’s role in web apps and explains why ECMAScript versioning matters when code is shipped without a framework build process.

Key terms: Vanilla JavaScript, core language, browser APIs, ECMAScript, versioning, transpiled

5.1 Versioning

This section explains how JavaScript features become standardized and why developers must check browser support rather than rely on proposal stages or ECMAScript edition names.

Key terms: TC39, Stage 0, Stage 4, ECMAScript, ECMAScript edition, browser support, MDN, Baseline, CanIUse, core language specification

5.2 Latest additions to the language

This section highlights which recent ECMAScript additions are useful in Vanilla Web projects and warns that compatibility depends on the target JavaScript engine.

Key terms: syntax, target engine, syntax errors, polyfilled, ES version, BigInt, async/await, modules, optional chaining

5.2.1 ESNext

Defines ESNext and explains why some of its features may already appear in newer browsers.

Key terms: ECMAScript Next, ESNext, Stage 3, Stage 4

5.3 Using a transpiler

This section explains how transpilers make newer JavaScript syntax usable in older engines and what trade-offs that conversion brings.

Key terms: transpiler, optional chaining, Babel, ES2019, compatibility, developer experience

5.4 Using polyfills

The section explains how polyfills provide missing APIs in older browsers, how they differ from transpilers, and why targeted polyfills suit Vanilla Web projects.

Key terms: polyfill, transpiler, runtime, modern API, targeted polyfills, Vanilla Web, includes method

5.5 ECMAScript Modules

This section explains how browser-native ECMAScript modules are loaded, linked, evaluated, and scoped.

Key terms: <script>, src, type="module", module scope, export, import, globalThis, entry module, module graph, construction

5.5.1 Named exports

This subsection explains that ES module exports are live bindings and distinguishes a module’s default export from its named exports.

Key terms: ESM exports, live bindings, default export, named export, curly braces

5.5.2 Importing modules

This subsection explains how modules import exports, what paths browser imports accept, and how a module can combine imports and re-export them.

Key terms: import keyword, import declarations, relative and absolute URLs, import map, re-exporting, bundlers

5.5.3 Import Maps

This section explains how import maps let browsers resolve bare module specifiers and when a bundler may still be useful.

Key terms: bare specifier, Import Maps, bundler, code splitting, minification, tree-shaking

5.5.4 Top-level await

This section explains how top-level await initializes a module, delays importing modules, and can create costly chains of waits.

Key terms: top-level await, configuration, one-time initialization, module, dependency, lazy-load, first paint

5.5.5 Preloading and execution order

Explains how modulepreload affects module fetching without executing code, and how async changes the execution order of module scripts.

Key terms: module graph, modulepreload, static import, dynamic import, module scripts, defer, async, dependency graph

5.5.6 Lazy loading

This subsection explains on-demand module loading with dynamic import() and notes that preloading can reduce its latency.

Key terms: dynamic import(), Promise, module namespace object, await import(), preloading, on demand, latency

5.5.7 Error handling and timeouts for dynamic imports

Dynamic imports use the network, so callers should handle failures and consider timeouts.

Key terms: dynamic imports, import(), lazyImport, timeout, promise

5.5.8 Import attributes and JSON modules

Explains how import attributes load JSON and CSS modules, why declared types matter for security and caching, and what to do when targeting older engines.

Key terms: import attributes, with { type: 'json' }, default export, module namespace, type, security check, declared type, module’s identity in the cache, single-evaluation, shared-instance

5.5.9 Re-exports and module organization

Re-exporting from index modules gives features a clear public API and stable import paths, with a tree-shaking consideration for bundler users.

Key terms: re-exporting, index modules, public API surfaces, import paths, tree shaking, explicit named re-exports, export *, barrels

5.5.10 Caching, single evaluation, and side effects

This subsection explains how repeated imports share a module’s evaluation and state, why setup should be explicit, and when a classic fallback may be needed.

Key terms: module URL, namespace object, state, side effects, top-level side effects, init(), entry point, load order, classic fallback, modern module entry

5.5.11 Practical rules of thumb

Provides practical choices for loading ES modules and explains how those choices support a framework-free project architecture.

Key terms: static imports, dynamic import(), preload, critical path, top-level await, first render, bare specifiers, import map, stable URLs, ES modules

5.6 Modern JavaScript Essentials

The section frames ES2015 and async/await as familiar foundations for the later JavaScript features used in Vanilla Web apps.

Key terms: modern JavaScript, ES2015/ES6, async/await, boilerplate

5.6.1 Optional chaining and nullish coalescing

This section introduces optional chaining and nullish coalescing as ways to reduce defensive code when accessing properties and choosing defaults.

Key terms: optional chaining, ?., nullish coalescing, ??, ||, null, undefined

5.6.2 Logical assignment operators

This section explains when each logical assignment operator assigns a value and why choosing between falsy and nullish defaults matters.

Key terms: logical assignment operators, ||=, &&=, ??=, falsy, truthy, short-circuit, right-hand side, left-hand side

5.6.3 Destructuring + rest/spread in practice

Shows how destructuring with object rest/spread helps extract and forward properties, while warning that object spread makes only a shallow copy.

Key terms: destructuring, object rest/spread, rest and spread operators, object spread, shallow, nested structures

5.6.4 Classes with public & private fields

This section introduces modern class fields and explains why #private members provide stronger encapsulation than underscore-named properties.

Key terms: private #value, _value, parse time, public fields, private fields, private methods/accessors, static fields, constructor boilerplate

5.6.5 Cleaner errors: optional catch binding and error cause

5.6.6 Small quality-of-life wins

This section highlights small JavaScript features that make common object, number, and string operations cleaner.

Key terms: Object.fromEntries, Object.entries, Object.values, Object.hasOwn, obj.hasOwnProperty, Numeric separators, String.prototype.replaceAll, String.prototype.matchAll

5.7 Collection Management

Introduces JavaScript collections as built-in tools for common Vanilla Web app data tasks.

Key terms: collections, arrays, sets, maps

5.7.1 Arrays

Defines arrays, identifies newer methods that simplify common operations, and recommends non-mutating copy methods when appropriate.

Key terms: Array, ordered, zero-indexed, includes, find, findIndex, flat, flatMap, at, copy methods

5.7.2 Sets

This section introduces Sets as a way to store unique values and names modern operations available on them.

Key terms: Set, unique values, union, intersection, difference, symmetricDifference

5.7.3 Maps

Introduces Maps as key–value stores with flexible key types, insertion order, and iteration APIs.

Key terms: Map, key–value store, insertion order, keys(), values(), entries()

5.7.4 Weak collections: memory-friendly

Explains how weak collections let metadata be associated with objects without keeping those objects alive.

Key terms: WeakMap, WeakSet, garbage collection, weakly, strong reference, metadata

5.8 Functional Programming

Introduces functional programming as a practical set of ideas already common in Vanilla JavaScript.

Key terms: functional programming, FP, side effects, Vanilla

5.8.1 Array transformations

This section presents array methods that take functions as a declarative alternative to manual loops.

Key terms: FP, higher-order methods, declarative, array methods

5.8.2 Pure functions and immutability

Defines a pure function and explains why pairing purity with immutability makes code easier to reason about.

Key terms: pure function, inputs, external state, immutability

5.8.3 Function composition

This subsection explains that plain JavaScript can chain small functions into readable, testable pipelines.

Key terms: function composition, pipelines, plain JavaScript

5.8.4 Everyday benefits

This section explains the everyday benefits of using a few functional programming practices in Vanilla Web code.

Key terms: pure functions, immutability, array methods, optional chaining, spread, functional style

5.9 Error Management

This section explains why Vanilla JavaScript apps need consistent error management without a framework handling errors for them.

Key terms: runtime, asynchronously, Vanilla project, silent failures

5.9.1 Exceptions and try/catch

This section explains how try/catch handles synchronous errors, how finally supports cleanup, and when a catch binding can be omitted.

Key terms: try/catch, synchronous code, finally, catch binding, error object, ES2019

5.9.2 Error objects

This section explains JavaScript error objects, how a cause preserves an original error, and when AggregateError represents multiple errors.

Key terms: Error, TypeError, ReferenceError, RangeError, cause, err.cause, AggregateError

5.9.3 Asynchronous errors

This subsection explains how to handle promise rejections and errors from await rather than leaving them unhandled.

Key terms: promise rejections, async/await, unhandledrejection event, try/catch

5.9.4 Global handlers

This section identifies the browser’s global error handlers and explains their limited role as last-resort logging and monitoring safety nets.

Key terms: window.onerror, window.onunhandledrejection, logging, telemetry, structured error management

5.9.5 Practical guidance for error management

Summarizes where to handle errors in Vanilla JavaScript and why explicit handling makes applications more predictable and easier to debug.

Key terms: try/catch, promise rejections, catch handlers, Error instances, cause option, rethrowing, global error events, diagnostics, reporting

5.10 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 4: Vanilla CSS Chapter 6: The document object model API →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.