Share E-Book

JavaScript Cookbook Programming the Web (Scott, Adam, MacDonald, Matthew, Powers etc.)(Z-Library)

Author Scott, Adam, MacDonald, Matthew, Powers, Shelley

JavaScript
Language English

Why reinvent the wheel every time you run into a problem with JavaScript? This cookbook is chock-full of code recipes that address common programming tasks as well as techniques for building components and apps that work in any browser. This cookbook provides adaptable code samples that you can easily add to almost any project. You'll get the job done faster and learn more about JavaScript in the process. You'll also learn how to take advantage of the latest features in ECMAScript 2015 and beyond, including the new JavaScript data structures, progressive web apps, generator functions, and more. Authors John Paxton, Adam Scott, and Shelley Powers provide recipes to help you use these features to build high-quality application interfaces. Create interactive web and desktop applications Work with JavaScript types, such as strings, numbers, and Booleans Improve your understanding of JavaScript functions, including arrow functions and generators Work with rich media in JavaScript, including audio, video, and SVGs Leverage the latest and greatest JavaScript libraries to rapidly prototype applications Use JavaScript anywhere with Node.js Access and manipulate remote data with REST, GraphQL, and Fetch Fully realize the capabilities of maps, sets, arrays, and iterables Perform asynchronous operations with Promises and async/await.

Format EPUB
Size 1.0 MB
155
Views
0
Downloads
0.00
Total Donations

AI Guide

AI Reading Assistant

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

Full assistant
AI guide
【One-Line Pitch】 A practical, recipe-driven guide to modern JavaScript—covering everything from error handling and DOM manipulation to the latest ECMAScript features—for developers who want battle-tested solutions they can drop into real projects without reinventing the wheel. 【Book Arc】 - **Opening (~0%–12%)**: Introduces the cookbook format and the book's scope—practical recipes for common JavaScript tasks, with a focus on modern ECMAScript 2015+ features. The early chapters establish the book's philosophy: solve real problems with adaptable, production-ready code. - **Early (~12%–31%)**: Dives deep into JavaScript error handling. Covers the eight Error types, how to catch errors by subtype using `instanceof`, throwing informative TypeErrors and RangeErrors, and creating custom error subclasses with ES2015 class syntax. Emphasizes that errors should clarify failures, not replace user-facing validation. - **Middle (~31%–46%)**: Transitions to working with the DOM. Explains the document tree structure, using `document.getElementById()` for precise element access, and traversing parent/child nodes via `parentNode` and `childNodes`. Discusses the evolution from DOM Level 0 to standardized DOM Levels 2 and 3. - **Middle (~46%–58%)**: Continues DOM manipulation with modern selector APIs. Covers `querySelectorAll()` and iterating results with `forEach()`, including polyfills for older browsers. Includes practical recipes like summing values in HTML table columns using `parseFloat()` and CSS selectors like `td:nth-of-type(2)`. 【Key Takeaways】 - **JavaScript has eight Error types, and knowing them improves debugging** (Early): The parent `Error` type plus seven subtypes (EvalError, RangeError, ReferenceError, SyntaxError, TypeError, etc.) each signal a different failure mode. Checking subtypes with `instanceof` in a single catch block is the only way to filter errors, since JavaScript lacks multi-catch syntax. - **Throw informative errors with context** (Early): When creating errors, include the method name and reason in the message, like `` `Problem in ${method}, ${reason}` ``. This illuminates the failure path for whoever debugs the code later—likely yourself. - **Use TypeError and RangeError deliberately, not for form validation** (Early): TypeError signals wrong value types; RangeError is specifically for out-of-range numeric values. Never use errors for user input validation—use native form APIs and event hooks instead, since errors often don't render visibly and can break page layout. - **Custom error subclasses should stay conservative** (Early): When subclassing Error with ES2015 class syntax, keep the API familiar—standard properties like `name` and `message` should work as expected. Add custom properties sparingly, and remember some browsers expect the first three constructor arguments to be message, filename, and line number. - **Wrap JSON.parse to create domain-specific errors** (Middle): JSON parsing failures surface as generic SyntaxErrors. By creating a `JSONParseError` subclass and a wrapper function like `betterParse()`, you can re-throw SyntaxErrors as more meaningful, testable error types without losing other unexpected errors. - **The DOM is a tree—traverse it with parent and child node properties** (Middle): Every element except the root has a `parentNode`, and `childNodes` returns a NodeList that may include text nodes, not just elements. Use `document.getElementById()` for the most restrictive, efficient element access. - **Modern selector APIs simplify DOM queries** (Middle): `document.querySelectorAll()` with CSS selectors like `td:nth-of-type(2)` or `td + td` replaces verbose traversal. Combine with `forEach()` for clean iteration, and add a polyfill if you need to support older browsers lacking NodeList.forEach. 【Reading Tips】 - **Skim the error-handling chapters if you're experienced** (~12%–31%): The core concepts—subtype checking, custom errors, informative messages—are valuable, but the recipes are straightforward. Focus on the custom error subclass pattern and the JSON.parse wrapper, which are genuinely reusable. - **Deep-read the DOM chapters for selector mastery** (~31%–58%): The progression from `getElementById` to `querySelectorAll` is essential for modern vanilla JavaScript. Pay special attention to the table-summing recipe—it demonstrates real-world selector patterns you'll use constantly. - **Watch for the "why" behind each recipe**: The book explains not just how to solve a problem but why the solution works, like why `parseFloat()` beats `parseInt()` for table values. These insights transfer to your own code. - **Treat this as a reference, not a cover-to-cover read**: The cookbook format means you can jump to specific recipes as problems arise. The table of contents and recipe titles are your best navigation tools. - **Note the early-release caveats**: This appears to be an early release edition, so some chapter numbers and content may differ from the final published version. Don't rely on cross-references to other chapters. 【Coverage Limits】 The excerpts cover only the error-handling and DOM-manipulation chapters in detail. Topics mentioned in the blurb—Node.js, REST/GraphQL, async/await, maps/sets/iterables, and rich media—are not covered in the available material.

Passage locations

Excerpt 1
Share an Attribute 2.6. Accessing All Images in a Page 2.7. Discovering All Images in Articles Using the Selectors API 2.8. Setting an Element’s Style Attrib...
View in text
Excerpt 2
ast give us a little more information about what went wrong. The seven Error subtypes: EvalError: thrown by use of the built-in function eval() InternalError...
View in text
Excerpt 3
your code, and should be handled in a user-friendly manner. There are both native APIs for form validation, as well as customizable, event-based hooks for va...
View in text
Excerpt 4
ardized versions of the DOM, such as the DOM Levels 2 and 3. Originally, though, a de facto technique was to access the elements through the browser object m...
View in text

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
Back to List