Professional JavaScript for Web Developers [Team-IRA] [5 ed.]
1394193211, 9781394193219
Update and upgrade your JavaScript skillset for ES 2023 with the ultimate JavaScript guide for pros
Professional JavaSc
126
28
7MB
English
Pages 1104
[1105]
Year 2023
Report DMCA / Copyright
DOWNLOAD PDF FILE
Table of contents :
Cover Page
Title Page
Copyright Page
Contents
Foreword
Introduction
Who This Book is For
What This Book Covers
How This Book is Structured
What You Need To Use This Book
Chapter 1 What Is JavaScript?
A Short History
Javascript Implementations
ECMAScript
The Document Object Model
The Browser Object Model
Summary
Chapter 2 JavaScript in HTML
The Element
Tag Placement
Deferred Scripts
Asynchronous Scripts
Dynamic Script Loading
Inline Code Versus External Files
Document Modes
The Element
Summary
Chapter 3 Language Basics
Syntax
Case-Sensitivity
Identifiers
Comments
Strict Mode
Statements
Keywords and Reserved Words
Variables
The var Keyword
let Declarations
const Declarations
Declaration Styles and Best Practices
Data Types
The typeof Operator
The Undefined Type
The Null Type
The Boolean Type
The Number Type
The BigInt Type
The String Type
The Symbol Type
The Object Type
Operators
Unary Operators
Bitwise Operators
Boolean Operators
Multiplicative Operators
Exponentiation Operator
Additive Operators
Relational Operators
Equality Operators
Conditional Operator
Nullish Coalescing Operator
Assignment Operators
Comma Operator
Statements
The if Statement
The do-while Statement
The while Statement
The for Statement
The for-in Statement
The for-of Statement
Labeled Statements
The break and continue Statements
The with Statement
The switch Statement
Functions
Summary
Chapter 4 Variables, Scope, and Memory
Primitive and Reference Values
Dynamic Properties
Copying Values
Argument Passing
Determining Type
Execution Context and Scope
Scope Chain Augmentation
Variable Declaration
Garbage Collection
Performance
Managing Memory
Summary
Chapter 5 Basic Reference Types
The Date Type
Inherited Methods
Date-Formatting Methods
Date/Time Component Methods
The Regexp Type
RegExp Instance Properties
RegExp Instance Methods
Primitive Wrapper Types
The Boolean Type
The Number Type
The String Type
Singleton Built-In Objects
The Global Object
The Math Object
Summary
Chapter 6 Advanced Reference Types
The Object Type
The Array Type
Creating Arrays
Array Holes
Indexing into Arrays
Detecting Arrays
Iterator Methods
Copy and Fill Methods
Spread Operator
Rest Operator
Conversion Methods
Stack Methods
Queue Methods
Reordering and Sorting Methods
Manipulation Methods
Search and Location Methods
Iterative Methods
Reduction Methods
Flattening Methods
Typed Arrays
History
Using ArrayBuffers
DataViews
Typed Arrays
The Map Type
Basic API
Order and Iteration
Choosing Between Objects and Maps
The Set Type
Basic API
Order and Iteration
Weak References
WeakRef
FinalizationRegistry
The Weakmap Type
Basic API
Weak Keys
Non-Iterable Keys
Utility
The Weakset Type
Basic API
Weak Keys
Non-Iterable Values
Utility
Iteration and Spread Operators
Summary
Chapter 7 Iterators and Generators
Introduction to Iteration
The Iterator Pattern
The Iterable Protocol
The Iterator Protocol
Custom Iterator Definition
Early Termination of Iterators
Generators
Generator Basics
Interrupting Execution with yield
Using a Generator as the Default Iterator
Early Termination of Generators
Asynchronous Iteration
Creating and Using an Async Iterator
Understanding the Async Iterator Queue
Async Iterator reject() Handling
Manual Async Iteration Using next()
Top-Level Async Loops
Implementing Observables
Summary
Chapter 8 Objects, Classes, and Object-Oriented Programming
Understanding Objects
Types of Properties
Accessing Object Properties
Chaining Properties
Object Static Methods
Controlling Object Mutability
Defining Multiple Properties
Reading Property Attributes
Merging Objects
Object Identity and Equality
Enhanced Object Syntax
Object Destructuring
Rest Operator
Spread Operator
Object Creation
Overview
The Function Constructor Pattern
The Prototype Pattern
Prototype Inheritance
Classes
Class Definition Basics
Class Composition
The Class Constructor
Instance, Prototype, and Class Members
Class Inheritance
Summary
Chapter 9 Proxies and Reflect
Proxy Fundamentals
Creating a Passthrough Proxy
Defining Traps
Trap Parameters and the Reflect API
Trap Invariants
Revocable Proxies
Utility of the Reflect API
Proxying a Proxy
Proxy Considerations and Shortcomings
Proxy Traps and Reflect Methods
get()
set()
has()
defineProperty()
getOwnPropertyDescriptor()
deleteProperty()
ownKeys()
getPrototypeOf()
setPrototypeOf()
isExtensible()
preventExtensions()
apply()
construct()
Proxy Patterns
Tracking Property Access
Hidden Properties
Property Validation
Function and Constructor Parameter Validation
Data Binding and Observables
Summary
Chapter 10 Functions
Arrow Functions
Function Names
Understanding Arguments
Arguments in Arrow Functions
No Overloading
Default Parameter Values
Default Parameter Scope and Temporal Dead Zone
Spread Arguments and Rest Parameters
Spread Arguments
Rest Parameter
Function Declarations Versus Function Expressions
Functions as Values
Function Internals
arguments
this
caller
new.target
Function Properties and Methods
Using apply(), call(), and bind()
Serializing Functions
Recursion
Tail Call Optimization
Tail Call Optimization Requirements
Coding for Tail Call Optimization
Closures
The this Object
Memory Leaks
Immediately Invoked Function Expressions
Summary
Chapter 11 Promises and Async/Await
Introduction to Asynchronous Programming
Synchronous vs. Asynchronous JavaScript
Legacy Asynchronous Programming Patterns
Promises
The Promises/A+ Specification
Promise Basics
Promise Instance Methods
Rejecting Promises and Rejection Error Handling
Promise Chaining and Composition
Avoiding Unhandled Rejections
Promise Extensions
Async Functions
Async Function Basics
Strategies for Async Functions
Summary
Chapter 12 The Browser Object Model
The Window Object
The Global Scope
The globalThis property
Window Relationships
Window Position and Pixel Ratio
Window Size
Window Viewport Position
Navigating and Opening Windows
Intervals and Timeouts
System Dialogs
The Location Object
Manipulating the Location
The Navigator Object
Registering Handlers
The Screen Object
The History Object
Navigation
History State Management
Summary
Chapter 13 The Document Object Model
Hierarchy of Nodes
The Node Type
The Document Type
The Element Type
The Text Type
The Comment Type
The CDATASection Type
The DocumentType Type
The DocumentFragment Type
The Attr Type
Working with The Dom
Dynamic Scripts
Dynamic Styles
Using NodeLists
Selectors API
The querySelector() Method
The querySelectorAll() Method
The matches() Method
Element Traversal
HTML5
Class-Related Additions
Focus Management
Changes to HTMLDocument
Character Set Properties
Custom Data Attributes
Markup Insertion
The scrollIntoView() Method
The children Property
The contains() Method
Markup Insertion
Summary
Chapter 14 DOM Extensions
Styles
Accessing Element Styles
Working with Style Sheets
Element Dimensions
Traversals
NodeIterator
TreeWalker
Ranges
Ranges in the DOM
Simple Selection in DOM Ranges
Complex Selection in DOM Ranges
Interacting with DOM Range Content
Inserting DOM Range Content
Collapsing a DOM Range
Comparing DOM Ranges
Cloning DOM Ranges
Cleanup
Observer APIs
Observer API Methods
Resize Observers
Intersection Observers
Mutation Observers
Observer Performance
Summary
Chapter 15 Events
Event Flow
Event Bubbling
DOM Event Flow
Event Handlers
HTML Event Handlers
DOM Level 0 Event Handlers
DOM Level 2 Event Handlers
The Event Object
The DOM Event Object
Event Types
UI Events
Focus Events
Mouse and Wheel Events
Keyboard and Text Events
Composition Events
Mutation Events
HTML5 Events
Device Events
Touch and Gesture Events
Event Reference
Memory and Performance
Event Delegation
Removing Event Handlers
Simulating Events
DOM Event Simulation
Summary
Chapter 16 Animation and Graphics with Canvas
Using Requestanimationframe
Early Animation Loops
Problems with Intervals
requestAnimationFrame
cancelAnimationFrame
Performance Throttling with requestAnimationFrame
Basic Canvas Usage
The 2D Context
Fills and Strokes
Drawing Rectangles
Drawing Paths
Drawing Text
Transformations
Drawing Images
Shadows
Gradients
Patterns
Working with Image Data
Compositing
WebGL
The WebGL Context
WebGL Basics
WebGL1 versus WebGL2
Summary
Chapter 17 Scripting Forms
Form Basics
Submitting Forms
Resetting Forms
Form Fields
Scripting Text Boxes
Text Selection
Input Filtering
HTML5 Constraint Validation API
Scripting Select Boxes
Options Selection
Adding Options
Removing Options
Moving and Reordering Options
Rich Text Editing
Using contenteditable
Interacting with Rich Text
Rich Text Selections
Rich Text in Forms
Summary
Chapter 18 JavaScript APIs
Atomics and SharedArraybuffer
SharedArrayBuffer
Atomics Basics
Clipboard API
Permissions
Text Read and Write
Clipboard Events
Working with Non-Text Data
Cross-Context Messaging
Encoding API
Encoding Text
Decoding Text
Blob And File APIs
The File Type
The FileReader Type
The FileReaderSync Type
Blobs and Partial Reads
Object URLs and Blobs
Drag-and-Drop File Reading
Fullscreen API
Geolocation API
Device APIs
Browser and Operating System Identification
Hardware
Media Elements
Properties
Events
Custom Media Players
Codec Support Detection
The Audio Type
Notifications API
Notification Permissions
Showing and Hiding Notification
Notification Lifecycle Callbacks
Page Visibility API
Streams API
Introduction to Streams
Readable Streams
Writable Streams
Transform Streams
Piping Streams
URL APIs
The URL Object
The URLSearchParams Object
Timing APIs
High Resolution Time API
Performance Timeline API
Web Components
HTML Templates
Shadow DOM
Custom Elements
The Web Cryptography API
Random Number Generation
Using the SubtleCrypto Object
Summary
Chapter 19 Error Handling and Debugging
Browser Error Reporting
Desktop Consoles
Mobile Consoles
Error Handling
The try-catch Statement
Throwing Errors
The error Event
Error Handling Strategies
Identifying Where Errors Might Occur
Common Sources of Error
Distinguishing Between Fatal and Nonfatal Errors
Debugging Techniques
Logging Messages to a Console
Understanding the Console Runtime
Using the JavaScript Debugger
Logging Messages to the Page
Shimming Console Methods
Throwing Errors
Summary
Chapter 20 JSON
Syntax
Simple Values
Objects
Arrays
Parsing and Serialization
The JSON Object
Serialization Options
Parsing Options
Summary
Chapter 21 Network Requests and Remote Resources
The Fetch Api
Basic API Utilization
Common Fetch Patterns
The Headers Object
The Request Object
The Response Object
Requests, Responses, and the Body Mixin
Cross-Origin Resource Sharing
Preflighted Requests
Credentialed Requests
The Beacon API
Web Sockets
The API
Sending/Receiving Data
Other Events
The Eventsource API
Summary
Chapter 22 Client-Side Storage
Cookies
Restrictions
Cookie Parts
Cookies in JavaScript
Cookie Considerations
Web Storage
The Storage Type
The sessionStorage Object
The localStorage Object
The storage Event
Limits and Restrictions
IndexedDB
Databases
Object Stores
Transactions
Insertion
Querying with Cursors
Key Ranges
Setting Cursor Direction
Indexes
Concurrency Issues
Limits and Restrictions
Wrapper Libraries
Summary
Chapter 23 Modules
Understanding The Module Pattern
Module Identifiers
Module Dependencies
Module Loading
Entry Points
Asynchronous Dependencies
Programmatic Dependencies
Static Analysis
Circular Dependencies
Working with Pre-ES6 Module Loaders
CommonJS
Asynchronous Module Definition
Universal Module Definition
Module Loader Deprecation
Working with ECMAScript Modules
Module Tagging and Definition
Module Loading
Module Behavior
Module Exports
Module Imports
Import Metadata
Dynamic Imports
Module Side Effects
Module Passthrough Exports
Import Maps
Worker Modules
Backwards Compatibility
Summary
Chapter 24 Workers
Introduction to Workers
Comparing Workers and Threads
Types of Workers
The WorkerGlobalScope
Dedicated Workers
Dedicated Worker Basics
Dedicated Workers and Implicit MessagePorts
Understanding the Dedicated Worker Lifecycle
Configuring Worker Options
Creating a Worker from Inline JavaScript
Dynamic Script Execution Inside a Worker
Delegating Tasks to Subworkers
Handling Worker Errors
Communicating with a Dedicated Worker
Worker Data Transfer
Worker Pools
Shared Workers
Shared Worker Basics
Understanding the Shared Worker Lifecycle
Connecting to a Shared Worker
Service Workers
Service Worker Use Cases
Service Worker Basics
The Service Worker Cache
Service Worker Clients
Service Workers and Consistency
Understanding the Service Worker Lifecycle
Inversion of Control and Service Worker Persistence
Managing Service Worker File Caching with updateViaCache
Forced Service Worker Operation
Service Worker Messaging
Intercepting a fetch Event
Push Notifications
Summary
Chapter 25 Best Practices
Maintainability
What Is Maintainable Code?
Code Conventions
Loose Coupling
Programming Practices
Performance
Don’t Over-Optimize
Be Scope-Aware
Problematic Language Features
Choose the Right Approach
Minimize Statement Count
Optimize DOM Interactions
Strong Typing
Deployment
Build Process
Validation
Compression
Summary
Appendix A ES.Next
Array Find from Last Methods
Hashbang/Shebang Grammar
Symbols as WeakMap Keys
Change Array by Copy
Appendix B Strict Mode
Opting-In
Classes and Modules
Variables
Objects
Functions
Function Parameters
Using eval()
eval and ARGUMENTS
Coercion of This
Other Changes
Appendix C JavaScript Libraries and Frameworks
Frameworks
React
Angular
Vue
Alpine.js
Ember
Meteor
Backbone.js
Useful Libraries
jQuery
Google Closure Library
Underscore.js
Lodash
D3
three.js
Anime.js
Chart.js
Leaflet
Axios
Rxjs
Appendix D JavaScript Tools
Package Managers
npm
Yarn
Bower
Module Loaders
SystemJS
RequireJS
Module Bundlers
Webpack
Parcel
Rollup
Compilation/Transpilation Tools and Static Type Systems
Babel
Google Closure Compiler
TypeScript
Flow
High-Performance Script Tools
WebAssembly
asm.js
Emscripten and LLVM
Editors
Sublime Text
Atom
Brackets
Visual Studio Code
WebStorm
Build Tools, Automation Systems, and Task Runners
npm
Grunt
Gulp
Linters and Formatters
ESLint
Google Closure Compiler
JSLint
JSHint
Clang Format
Minifiers
Uglify
Google Closure Compiler
JSMin
Unit Testing
Mocha
Jest
Jasmine
qUnit
JsUnit
Documentation Generators
ESDoc
documentation.js
Docco
JsDoc Toolkit
Index
EULA