liveBook · Manning

Chapter 2: Chapter 2. Building the page at runtime

What you will learn in chapter 2 of Secrets of the JavaScript Ninja, Second Edition

The introduction places JavaScript in the browser-based lifecycle of a client-side web application and identifies the basic roles of HTML, JavaScript, events, the DOM, and the event loop.

After this chapter you will be able to

Section by section

Introduction

The introduction places JavaScript in the browser-based lifecycle of a client-side web application and identifies the basic roles of HTML, JavaScript, events, the DOM, and the event loop.

Key terms: client-side web applications, browser, HTML code, JavaScript code, events, DOM, event loop

2.1 The lifecycle overview

Outlines the client-side web application lifecycle and introduces an example that displays messages while the page loads and when users interact with it.

Key terms: client-side web application, page building, event handling, event handlers, addMessage, getElementById, mousemove event handler, click event handler

2.1 Do you know?

This section poses self-check questions about how browsers build pages and process events, without explaining the answers.

2.2 The page-building phase

Explains how the browser builds a page’s UI from a server response by alternating between HTML parsing and JavaScript execution.

Key terms: page-building phase, Document Object Model (DOM), script element

2.2.1 Parsing the HTML and building the DOM

The section explains how the browser builds a DOM from HTML, organizes its nodes, corrects invalid markup, and pauses construction when it reaches a script element.

Key terms: page-building phase, HTML, DOM, node, root html node, parent, children, siblings, blueprint, head element

2.2.2 Executing JavaScript code

This section explains how scripts run during page building, use browser-provided objects to change the DOM, and interact with HTML that has or has not yet been parsed.

Key terms: window object, document, DOM, browser APIs, global code, function code, addMessage, page-building phase, script node, DOM construction

2.3 Event handling

This section explains how browser events are registered, queued, and handled one at a time to make client-side applications interactive.

2.3.1 Event-handling overview

This section explains how the browser queues events and handles them one at a time, why slow handlers make pages unresponsive, and why event-driven code runs asynchronously.

Key terms: single-threaded execution model, event queue, event-handler function, event handlers, unresponsive web applications, asynchronous, events, global code

2.3.2 Registering event handlers

This section explains how to register event handlers and why addEventListener is preferable to assigning them to special properties.

Key terms: event handler, event-handler registration, special properties, addEventListener, event-handler function, mousemove, click

2.3.3 Handling events

This section traces how the event loop handles queued mouse events one at a time and how their handlers change the DOM.

Key terms: event queue, event loop, event handler, single-threaded execution model, DOM, mousemove handler, click handler, addMessage

2.4 Summary

2.5 Exercises

Where this is used later

Concepts explained in this chapter

← Chapter 1: Chapter 1. JavaScript is everywhere Chapter 3: Chapter 3. First-class functions for the novice: definitions and arguments →

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.