Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Adam D. Scott, Matthew MacDonald, Shelley Powers

Why reinvent the wheel every time you run into a problem with JavaScript? This cookbook is chock-full of code recipes for common programming tasks, along with techniques for building apps that work in any browser. You'll get adaptable code samples that you can add to almost any project--and you'll learn more about JavaScript in the process. The recipes in this book take advantage of the latest features in ECMAScript 2020 and beyond and use modern JavaScript coding standards. You'll learn how to: • Set up a productive development environment with a code editor, linter, and test server • Work with JavaScript data types, such as strings, arrays, and BigInts • Improve your understanding of JavaScript functions, including arrow functions, closures, and generators • Apply object-oriented programming concepts like classes and inheritance • Work with rich media in JavaScript, including audio, video, and SVGs • Manipulate HTML markup and CSS styles • Use JavaScript anywhere with Node.js • Access and manipulate remote data with REST, GraphQL, and Fetch • Get started with the popular Express application-building framework • Perform asynchronous operations with Promises, async/await, and web workers

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A problem-first recipe collection for developers who already know some JavaScript and want modern, copy-adaptable solutions for everyday tasks—from string handling and arrays to Node.js, async work, and browser APIs. Best for intermediate learners and working programmers who prefer "show me the code" over long theory. 【Book Arc】 - **Opening (~0%–10%)**: Sets up a productive workflow—code editor, linter, test server, and npm package management—so later recipes can be run and verified rather than just read. - **Early (~10%–35%)**: Core language fundamentals via recipes: string validation and comparison, regular expressions, cryptographically secure random numbers, BigInt for very large integers, and functional array processing. - **Middle (~35%–55%)**: Functions and objects in depth—passing functions as arguments, closures, optional-argument patterns via object literals and destructuring, plus array copying/slicing and immutability habits. - **Late (~55%–85%)**: Browser-side practice: manipulating HTML and CSS, rich media (audio, video, SVG), and remote data access through REST, GraphQL, and Fetch. - **Ending (~85%–100%)**: Node.js and application concerns—environment variables, taming callback hell, command-line utilities, keeping processes alive, scheduling tasks, WebSocket testing, and multiplatform modules. 【Key Takeaways】 - **Environment first, code second** (Opening): The book opens by treating editor, linter, and test server as prerequisites, which reframes "learning JavaScript" as building a repeatable workflow. - **Validate before you operate** (Early): Recipes stress checking that a value is genuinely a string (including the `String` object edge case) before calling string methods—short-circuit evaluation makes condition order matter. - **Prefer functional array methods, but know when to stop** (Early/Middle): `map`, `filter`, `reduce`, `some`, and `every` are the default because they encourage immutability and readability; the book explicitly says to fall back to loops for performance-critical or multi-array work, and to profile first. - **`slice` over `splice` as a habit** (Middle): Copying rather than mutating aligns with `const`-driven, immutable style; the book treats in-place mutation as a deliberate exception, not a default. - **BigInt exists because Number breaks silently** (Early): Past `Number.MAX_SAFE_INTEGER`, ordinary arithmetic produces quietly wrong results; BigInt is presented as the reliable alternative for large integers. - **Crypto randomness is not `Math.random()`** (Early): For anything security-sensitive, `Crypto.getRandomValues()` is the correct tool, with a documented workaround to convert its integer output into a fraction. - **Functions are values, and passing them has pitfalls** (Middle): The book highlights the classic `showMessage` vs. `showMessage()` mistake and shows object-literal optional arguments with destructuring as a clean API pattern. - **The same language, two runtimes** (Late/Ending): Browser APIs and Node.js are treated as parallel environments—recipes note when a browser-only object like `window` is unavailable and what to use instead. 【Reading Tips】 - Treat it as a reference, not a novel: jump to the recipe matching your current problem, then read the "Discussion" section, which carries most of the reasoning. - Deep-read the early chapters on strings, numbers, and arrays—the edge cases there (String objects, BigInt precision, `slice` vs. `splice`) are where experienced developers still get surprised. - Skim setup and tooling if your environment is already solid; return to it when a recipe's example won't run. - Watch for runtime markers: when a recipe uses `window` or DOM APIs, check whether the Node.js alternative is mentioned before copying it into server code. - Take away patterns, not snippets—the optional-argument object, the immutability default, and the functional-first array rule generalize beyond any single recipe. 【Coverage Limits】 This guide is synthesized from stratified excerpts covering the front matter, table of contents, and portions of the language, array, and function chapters; the later browser, media, data-fetching, and Node.js chapters are represented mainly by their titles, so specific recipes there are not summarized in detail.
Page 10
379 16.7 Copying Text to a User’s Clipboard 380 16.8 Enabling a Mobile-Like Notification in the Desktop Browser 382 16.9 Loading a File Locally in the Browse...
View in text
Excerpt 2
practice from any code you encounter than coding around it. However, if you need to accommodate possible String objects, you can use a more complex test like...
View in text
Excerpt 3
; // 9007199254740995 (excellent!) 72 | Chapter 3: Numbers Despite its name, getTime() does not return just the time. It returns the millisecond number that...
View in text
Excerpt 4
sage() { alert('You clicked the button 2 seconds ago'); } When you pass a function reference by name, make sure you don’t add a set of empty parentheses. Thi...
View in text
Excerpt 5
rozen(proxy) isSealed target Boolean Object.isSealed(proxy) isExtensible target Boolean Object.isExtensible(proxy) has target, name Boolean name in proxy has...
View in text
Excerpt 6
nstead, it will yield Promise objects that wrap the results. You can call Promise.then() to get the result, when it’s ready. Here’s an example that shows wha...
View in text
Excerpt 7
+C (Windows or Linux). 2. Click the DevTools Sources tab. 3. Select the JavaScript file from the file list. 4. Click the line number where you would like to...
View in text
Excerpt 8
equest: • A string • An encoded string, such as JSON or XML • A URLSearchParams object •
View in text
Tags
AI categories
ProgrammingJavaScriptWeb Technology
javascript
ISBN: 1492055727
Publish Year: 2021
Language: English
Pages: 538
File Format: PDF
File Size: 9.1 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…