Chapter 1: JavaScript is everywhere
The introduction explains how JavaScript evolved from a browser scripting language into a versatile language with better performance and development tools.
After this chapter you will be able to
- JavaScript’s expansion beyond browsers. Explain how JavaScript moved from its browser origins into many kinds of applications, identifying the changes the introduction credits for that expansion.
- Functions as first-class objects. Explain that JavaScript functions can be treated like other objects: assigned to variables, passed as arguments, and created by other functions.
- Prototype-based object orientation. Distinguish JavaScript’s prototype-based object orientation from the class-based approach of languages such as Java and C#, including what its class keyword represents.
- Single-threaded asynchronous code. State that JavaScript code runs in a single thread and that it uses callbacks and promises for asynchronous operations.
- Runtimes and engines. Distinguish a JavaScript runtime from its engine: a runtime is an environment that executes JavaScript, while its engine converts code into machine instructions and can optimize it as it runs.
- Host environment API bindings. Explain how runtime-provided API bindings let JavaScript interact with its host environment, using a browser and Node.js example.
- Changing ECMAScript standards. Describe how the ECMAScript standard shifted from relatively few changes to major new features in ES6/ES2015 and annual standards thereafter.
- Feature support across runtimes. Explain why a feature appearing in a new standard does not remove the need to check whether the runtimes executing your code support it, particularly for web pages.
- Transpilation for older standards. Explain that a transpiler transforms newer JavaScript into functionally equivalent code using features from older ECMAScript standards, and that TypeScript can transpile syntactic features to a chosen target version.
- Polyfills and transpiler pairing. Distinguish a polyfill from transpilation: a polyfill defines a missing runtime feature, such as Promise in Internet Explorer 11. Explain why polyfills may accompany transpilation and why Babel and TypeScript may be used together.
- Limits of compatibility tools. Explain why transpilation cannot make every new feature work in an older runtime, using regex lookbehind as the section’s example, and describe the resulting need to check target runtimes and test against them.
- Framework roles and selection. Explain what a JavaScript framework does in a web or server application and why choosing one that fits the project can save time.
- Evolution of web UI frameworks. Explain the shift from scripts that enhanced complete HTML pages to frameworks that let developers write HTML within JavaScript, and why the earlier approach made complex applications awkward.
- React virtual DOM updates. Trace how React uses a virtual DOM to update a page without requiring developers to manipulate the DOM directly.
- Client loading and server rendering. Explain why JavaScript-heavy pages can load slowly and how server-side rendering addresses that problem, including its implementation challenge.
- Server framework basics. Explain why Node.js web servers commonly use frameworks and what a server framework does at its simplest.
- Full-stack framework capabilities. Describe how the full-stack frameworks in this section connect web server and UI work, including their delivery and development features.
- Cross-platform JavaScript applications. Explain why JavaScript is appealing for desktop and mobile apps: one application can be deployed across multiple platforms, including the web, instead of writing a separate application in each platform’s language.
- Two app framework approaches. Distinguish frameworks that display an HTML-and-CSS interface in an embedded web view from React Native, which uses JSX constructs such as View to render UI components specific to the target platform.
- Best practices beyond language mastery. Explain why knowing JavaScript and ECMAScript standards is not enough on its own, and name the best practices the section identifies.
- Flexible typing and surprises. Explain that JavaScript often makes operations involving incompatible types work instead of throwing errors, sometimes producing counterintuitive results.
- TypeScript compile-time checks. Describe how TypeScript adds type annotations and uses its compiler to flag type-rule violations before runtime, such as passing a string to a function expecting a number.
- Linter rules for mistakes. Explain how configurable ESLint rules can flag confusing or error-prone JavaScript and TypeScript code, using shadowing or unreachable code as an example.
- Formatter role and benefits. Distinguish a formatter’s readability-focused changes from a linter’s rule checks, and explain why the section presents Prettier as useful.
- Runtime behavior verification. Explain why type checking and linting do not replace tests: tests run code and make assertions about its behavior.
- Unit and end-to-end tests. Distinguish unit tests from end-to-end tests by what each verifies, how each handles dependencies, and why an application benefits from both.
- Sources and costs of code bloat. Explain how common development choices create code bloat and why unused JavaScript can still slow a website.
- Shared codebase coordination costs. Explain why a single codebase that deploys as one unit can create conflicts for multiple teams, particularly when one team changes a dependency.
- Independent units and deployment. Describe why large projects may divide a codebase into units teams can update independently, and identify the deployment question this creates for parts of the same web page.
- Dependency compatibility and security risks. Describe how a dependency can cause problems through an unexpectedly breaking update, conflicting package versions, an ES module/CommonJS mismatch, or a supply chain attack.
Section by section
Introduction
The introduction explains how JavaScript evolved from a browser scripting language into a versatile language with better performance and development tools.
- JavaScript’s expansion beyond browsers: Explain how JavaScript moved from its browser origins into many kinds of applications, identifying the changes the introduction credits for that expansion.
Why it matters: This explains why a language created for browsers is now useful across many domains. - TypeScript’s supporting role: Distinguish TypeScript’s role as a development tool from JavaScript itself, and describe the improvements the introduction attributes to it.
Why it matters: It clarifies why the book includes TypeScript while remaining focused on JavaScript.
Key terms: JavaScript engines, ECMAScript standards process, Node.js runtime, TypeScript, IDE integration, static analysis
1.1 Understanding the JavaScript language
This section explains three ways JavaScript differs from familiar class-based languages: its first-class functions, prototype-based objects, and single-threaded execution.
- Functions as first-class objects: Explain that JavaScript functions can be treated like other objects: assigned to variables, passed as arguments, and created by other functions.
Why it matters: Treating functions as values opens up ways to organize JavaScript code. - Prototype-based object orientation: Distinguish JavaScript’s prototype-based object orientation from the class-based approach of languages such as Java and C#, including what its class keyword represents.
Why it matters: The familiar class keyword does not replace JavaScript’s underlying prototype model. - Single-threaded asynchronous code: State that JavaScript code runs in a single thread and that it uses callbacks and promises for asynchronous operations.
Why it matters: Single-threaded execution is useful context for why JavaScript code uses asynchronous patterns.
Key terms: first-class objects, functions, prototypes, class keyword, prototype-based object orientation, single-threaded, asynchronous operations, callbacks, promises
1.1.1 JavaScript runtimes and engines
This section explains how JavaScript runtimes execute code, provide access to their host environments, and sometimes support code written for other runtimes.
- Runtimes and engines: Distinguish a JavaScript runtime from its engine: a runtime is an environment that executes JavaScript, while its engine converts code into machine instructions and can optimize it as it runs.
Why it matters: The distinction explains how the same language can run in browsers, servers, and other places. - Host environment API bindings: Explain how runtime-provided API bindings let JavaScript interact with its host environment, using a browser and Node.js example.
Why it matters: It explains why the capabilities available to JavaScript code depend on where it runs. - Code across runtimes: Describe how some JavaScript code works across runtimes while other code targets one runtime, and how simulating another environment can let code cross over.
Why it matters: It helps explain both the portability of much JavaScript code and why runtime-specific code may need a simulated environment.
Key terms: runtime, engine, just-in-time compilation, API bindings, host environment, DOM, runtimes, jsdom, WebContainers
1.1.2 How does JavaScript get new features?
Explains how ECMAScript standards add JavaScript features and why runtime support matters when using them.
- ECMAScript and JavaScript names: Explain why ECMAScript and JavaScript refer, for practical purposes, to the same language and where each name is used.
Why it matters: It helps you recognize that an ECMAScript specification describes JavaScript. - Changing ECMAScript standards: Describe how the ECMAScript standard shifted from relatively few changes to major new features in ES6/ES2015 and annual standards thereafter.
Why it matters: The standards timeline explains why JavaScript keeps gaining features. - Feature support across runtimes: Explain why a feature appearing in a new standard does not remove the need to check whether the runtimes executing your code support it, particularly for web pages.
Why it matters: A feature is useful only if the runtime executing your code supports it.
Key terms: ECMAScript, JavaScript, ECMAScript Committee, ECMAScript standard, ES6, ES2015, runtimes, ECMAScript compatibility table
1.1.3 Transpilers and polyfills give us access to tomorrow’s JavaScript today
This section explains how transpilers and polyfills let code use newer JavaScript features in older runtimes, and why runtime compatibility still needs checking.
- Transpilation for older standards: Explain that a transpiler transforms newer JavaScript into functionally equivalent code using features from older ECMAScript standards, and that TypeScript can transpile syntactic features to a chosen target version.
Why it matters: It helps you distinguish code that can be rewritten for an older runtime from features that need another solution. - Polyfills and transpiler pairing: Distinguish a polyfill from transpilation: a polyfill defines a missing runtime feature, such as Promise in Internet Explorer 11. Explain why polyfills may accompany transpilation and why Babel and TypeScript may be used together.
Why it matters: Rewriting syntax alone may not provide the APIs your code uses. - Limits of compatibility tools: Explain why transpilation cannot make every new feature work in an older runtime, using regex lookbehind as the section’s example, and describe the resulting need to check target runtimes and test against them.
Why it matters: Checking your target runtimes prevents you from assuming that compatibility tools make every feature safe to use.
Key terms: transpiler, transpilation, ECMAScript standards, TypeScript compiler, polyfill, Promise, Babel, TypeScript, Regex lookbehind assertions, runtimes
1.2 Navigating the world of frameworks
Introduces frameworks as core application libraries and explains why choosing one that fits a project matters.
- Framework roles and selection: Explain what a JavaScript framework does in a web or server application and why choosing one that fits the project can save time.
Why it matters: This gives you a basis for thinking about framework choices before comparing particular frameworks.
Key terms: framework, library, open-source ecosystem
1.2.1 Web UI frameworks
This section explains how web UI frameworks evolved, how React updates pages, and the trade-offs involved in choosing and rendering frameworks.
- Evolution of web UI frameworks: Explain the shift from scripts that enhanced complete HTML pages to frameworks that let developers write HTML within JavaScript, and why the earlier approach made complex applications awkward.
Why it matters: This shift explains what modern web UI frameworks changed about building applications. - React virtual DOM updates: Trace how React uses a virtual DOM to update a page without requiring developers to manipulate the DOM directly.
Why it matters: It explains how React turns a description of the desired page into visible changes. - Framework ecosystem trade-off: Explain why the availability of component libraries can matter when choosing among React and competing web UI frameworks.
Why it matters: Framework selection depends on available reusable components, not just the framework's design. - Client loading and server rendering: Explain why JavaScript-heavy pages can load slowly and how server-side rendering addresses that problem, including its implementation challenge.
Why it matters: SSR addresses the wait for visible content, while introducing a requirement that can make implementation difficult.
Key terms: jQuery, React, JSX, virtual DOM, DOM, open-source ecosystem, component libraries, server-side rendering, SSR
1.2.2 Server frameworks
This section explains why Node.js web servers commonly use frameworks and compares minimal, feature-rich, CMS, and full-stack options.
- Server framework basics: Explain why Node.js web servers commonly use frameworks and what a server framework does at its simplest.
Why it matters: This gives you a basic way to understand what a web server framework adds to Node.js. - Server framework choices: Distinguish the minimal foundation offered by Express from the built-in functionality offered by Adonis and a CMS framework such as Keystone.
Why it matters: The examples show that choosing a framework also means choosing how much functionality comes built in. - Full-stack framework capabilities: Describe how the full-stack frameworks in this section connect web server and UI work, including their delivery and development features.
Why it matters: These features explain why a server framework can shape both the website visitors receive and the frontend developer’s workflow.
Key terms: Node.js, HTTP requests, server framework, handler functions, Express, Adonis, CMS framework, Keystone, ORM, full-stack frameworks
1.2.3 App frameworks
This section explains how JavaScript app frameworks support desktop and mobile development through web views or platform-specific UI components.
- Cross-platform JavaScript applications: Explain why JavaScript is appealing for desktop and mobile apps: one application can be deployed across multiple platforms, including the web, instead of writing a separate application in each platform’s language.
Why it matters: This is the main reason the section gives for using JavaScript beyond the web. - Two app framework approaches: Distinguish frameworks that display an HTML-and-CSS interface in an embedded web view from React Native, which uses JSX constructs such as View to render UI components specific to the target platform.
Why it matters: The distinction explains how JavaScript apps can use either familiar web UI or platform-specific UI. - Web-view app quality: Explain why the section says a web-view app need not look low-quality or disregard platform design standards.
Why it matters: It prevents treating the framework choice alone as a verdict on an app’s quality.
Key terms: write once, run anywhere, desktop and mobile applications, embedded web view, Electron, Ionic, React Native, JSX, View, component libraries, platform-specific design standards
1.3 Using current best practices
The section introduces best practices as a necessary complement to JavaScript knowledge for producing quality code.
- Best practices beyond language mastery: Explain why knowing JavaScript and ECMAScript standards is not enough on its own, and name the best practices the section identifies.
Why it matters: Language knowledge matters, but these practices are also part of writing quality code.
Key terms: best practices, type checking, linting/formatting, testing
1.3.1 Type checking
This section explains why JavaScript’s flexible typing can cause surprising errors and how TypeScript’s type annotations help catch them and inform development tools.
- Flexible typing and surprises: Explain that JavaScript often makes operations involving incompatible types work instead of throwing errors, sometimes producing counterintuitive results.
Why it matters: This is the problem that motivates type checking. - TypeScript compile-time checks: Describe how TypeScript adds type annotations and uses its compiler to flag type-rule violations before runtime, such as passing a string to a function expecting a number.
Why it matters: Checking a type mismatch before execution can prevent a surprising result in the running program. - Type information in editors: Explain that type annotations also give tools such as editors information they can show while you work, including a value’s type and a function’s expected arguments.
Why it matters: Type information can make code easier to inspect while writing it, not just catch mistakes.
Key terms: flexible type system, type coercion, TypeScript, type annotations, TypeScript compiler, compile time, runtime, type information, VS Code
1.3.2 Linting and formatting
This section explains how linters flag error-prone patterns and enforce style rules, while formatters make code consistently readable.
- Linter rules for mistakes: Explain how configurable ESLint rules can flag confusing or error-prone JavaScript and TypeScript code, using shadowing or unreachable code as an example.
Why it matters: Lint rules can alert you to code that may not behave as intended. - Lint style rules and fixes: Describe how linter rules can enforce code style and how some stylistic rules can fix code automatically instead of only reporting an error.
Why it matters: Style rules can keep a project consistent without requiring every correction by hand. - Formatter role and benefits: Distinguish a formatter’s readability-focused changes from a linter’s rule checks, and explain why the section presents Prettier as useful.
Why it matters: Consistent automatic formatting saves time and reduces disagreements about code layout.
Key terms: linter, ESLint, no-unreachable, no-shadow, shadowing, linter rules, capitalized-comments, auto-fix, formatter, Prettier
1.3.3 Testing
This section explains why running tests matters, how unit and end-to-end tests differ, and how the book uses console.assert for brief checks.
- Runtime behavior verification: Explain why type checking and linting do not replace tests: tests run code and make assertions about its behavior.
Why it matters: Tests check behavior that type checking and linting alone cannot verify. - Unit and end-to-end tests: Distinguish unit tests from end-to-end tests by what each verifies, how each handles dependencies, and why an application benefits from both.
Why it matters: The two kinds of tests catch different failures, so neither replaces the other. - Brief checks with console.assert: Describe the book’s use of console.assert for concise behavior checks and state what happens when its expected condition is false.
Why it matters: Recognizing these brief checks helps you read the book’s examples without mistaking them for a full testing approach.
Key terms: type checking, linting, test framework, assertions, unit tests, end-to-end tests, mocked, fixtures, dependencies, console.assert
1.4 Challenges facing JavaScript Ninjas
1.4.1 Performance
This section explains why slow JavaScript-heavy websites matter and how code bloat can make them slow despite improvements in JavaScript engines.
- Cost of slow websites: Explain why website performance matters to a business even though JavaScript engines have become more efficient.
Why it matters: A faster site can have measurable value beyond a better technical score. - Sources and costs of code bloat: Explain how common development choices create code bloat and why unused JavaScript can still slow a website.
Why it matters: Performance can suffer from code a visitor downloads even when that code is never executed.
Key terms: JavaScript engines, sluggish website, code bloat, packages, bandwidth, CPU
1.4.2 Collaboration at scale
This section explains the architectural tradeoff between a single shared codebase and independently updated units when multiple teams build one application.
- Shared codebase coordination costs: Explain why a single codebase that deploys as one unit can create conflicts for multiple teams, particularly when one team changes a dependency.
Why it matters: It explains why a simple deployment architecture can become difficult to coordinate at scale. - Independent units and deployment: Describe why large projects may divide a codebase into units teams can update independently, and identify the deployment question this creates for parts of the same web page.
Why it matters: It captures both the benefit of team independence and the tradeoff that architecture must address.
Key terms: single codebase, single unit, dependencies, separate units, independently, dependency changes, deploy
1.4.3 Dependency management
This section explains how third-party dependencies can introduce compatibility and security problems, and why developers should weigh those risks before adding a package.
- Dependency compatibility and security risks: Describe how a dependency can cause problems through an unexpectedly breaking update, conflicting package versions, an ES module/CommonJS mismatch, or a supply chain attack.
Why it matters: A package that seems useful can also disrupt an application or expose it to malicious code. - Dependency adoption tradeoff: Explain why a developer might read a third-party package’s code and compare the risks of adding it with the effort of implementing the needed functionality themselves.
Why it matters: Choosing a package is a tradeoff, not just a way to avoid writing code.
Key terms: dependencies, semantic versioning, indirect dependency, ES module, CommonJS, supply chain attack, third-party code, dependency
1.5 Summary
Where this is used later
- The Node.js runtime (chapter 3) · Provides context for using the Node.js runtime outside the browser.
- Type checking with TypeScript (chapter 2) · Introduces more detailed use of TypeScript for development.
- Functions as first-class objects (chapter 5) · Develops what it means for functions to be first-class objects.
- Classes as shorthand for prototypes (chapter 9) · Explains classes in relation to prototypes.
- The power of promises (chapter 8) · Develops the use of promises for asynchronous code.
- Using Node.js APIs (chapter 3) · Examines APIs provided by Node.js.
- Parsing HTML and building the DOM (chapter 4) · Uses the browser’s DOM environment.
- Targeting browsers with transpilation (chapter 13) · Motivates targeting browsers when building bundles.
Concepts explained in this chapter
- JavaScriptJavaScript is a high-level programming language standardized as ECMAScript and widely used for web and general-purpose software development.
- JavaScript runtimeA software environment that executes JavaScript and provides access to host-platform features.
- TypeScriptA statically typed superset of JavaScript that compiles to JavaScript.
- JSXJSX is a syntax extension that lets developers write XML-like markup within JavaScript code.
- promiseThe ECMAScript constructor and associated object abstraction for representing the eventual completion or failure of an asynchronous operation.
- server-side renderingA rendering technique in which HTML for a web page is generated on the server before being delivered to the browser.
- TypeScript compilerA tool that compiles TypeScript source code to JavaScript, optionally targeting a selected ECMAScript version.
- frameworkA reusable software system that provides structure and core functionality for applications.
- ReactReact is an open-source JavaScript library for building user interfaces from declarative components.
- virtual DOMA virtual DOM is an in-memory tree representation of a user interface that can be compared with the rendered document to determine updates.
- ECMAScript moduleA JavaScript module whose dependencies and shared bindings are declared using standardized import and export syntax.
- MapA JavaScript Map is a collection that associates keys with values and permits keys of arbitrary value types, including objects.
- Node.jsA standalone JavaScript runtime built around the V8 engine and designed for server-side and general-purpose applications.
- callbackA function supplied to another computation to be invoked when a specified event occurs or operation completes.
- closureA closure is a function together with access to variables from its surrounding lexical environment.
- first-class functionA function that can be treated as a value, including being assigned, passed as an argument, or returned.
- prototypeA prototype is an object from which another JavaScript object can inherit properties and methods.
- prototype-based object orientationPrototypal inheritance is an inheritance model in which objects obtain properties and methods through links to other objects.
- regular expressionA pattern notation used to match and manipulate text.
- setA collection of unique items with no duplicate membership.
- single-threaded execution modelSingle-threaded execution means JavaScript code executes in one thread of control at a time.
- type checkingThe process of verifying that expressions, values, and operations conform to a language's declared or inferred type rules.
- assertionAn assertion is a regular-expression condition that checks surrounding text without consuming it as part of the match.
- type coercionThe implicit conversion of a value from one type to another during an operation or expression evaluation.
- type hintsSyntax attached to a TypeScript declaration or expression that explicitly specifies expected types and can supply information for type checking and inference.
- ESLintAn open-source linter for JavaScript and TypeScript with configurable rules and automatic fixes.
- PrettierPrettier is an opinionated source-code formatter for JavaScript and related languages.
- linter ruleA configurable static-analysis condition that determines when a linter reports a source-code construct.
- lazy initializationDeferred loading is the postponement of loading a dependency until it is needed or otherwise appropriate.
- tree-shakingTree-shaking is a build-time optimization that removes unused code from a program by analyzing its module dependencies and exports.
- dependencyA software component or package that another component requires in order to build or run.
- classA class is JavaScript syntax for defining object construction and behavior that is implemented through the prototype system.
- HTMLThe standard markup language for structuring documents and content on the web.
- lookbehind assertionA lookbehind is a regular-expression assertion that checks for a pattern immediately before the current position without consuming text.
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.
