1 VALUES, TYPES, AND OPERATORS

  • Values
  • Numbers
  • Arithmetic
  • Special Numbers
  • Strings
  • Unary Operators
  • Boolean Values
  • Comparisons
  • Logical Operators
  • Undefined Values
  • Automatic Type Conversion
  • Short-Circuiting of Logical Operators
  • Summary

2 PROGRAM STRUCTURE

  • Expressions and Statements
  • Variables
  • Keywords and Reserved Words
  • The Environment
  • Functions
  • The console
  • Return Values
  • Prompt and Confirm
  • Control Flow
  • Conditional Execution
  • while and do Loops
  • Indenting Code
  • for Loops
  • Breaking Out of a Loop
  • Updating Variables Succinctly
  • Dispatching on a Value with switch
  • Capitalization
  • Comments
  • Summary
  • Exercises
    • Looping a Triangle
    • FizzBuzz
    • Chess Board

3 FUNCTIONS

  • Defining a Function
  • Parameters and Scopes
  • Nested Scopes
  • Functions as Values
  • Declaration Notation
  • The Call Stack
  • Optional Arguments
  • Closure
  • Recursion
  • Growing Functions
  • Functions and Side Effects
  • Summary
  • Exercises
    • Minimum
    • Recursion
    • Bean Counting

4 DATA STRUCTURES: OBJECTS AND ARRAYS

  • The Weresquirrel
  • Data Sets
  • Properties
  • Methods
  • Objects
  • Mutability
  • The Lycanthrope’s Log
  • Computing Correlation
  • Objects as Maps
  • The Final Analysis
  • Further Arrayology
  • Strings and Their Properties
  • The arguments Object
  • The Math Object
  • The Global Object
  • Summary
  • Exercises
    • The Sum of a Range
    • Reversing an Array
    • A List
    • Deep Comparison

5 HIGHER-ORDER FUNCTIONS

  • Abstraction
  • Abstracting Array Traversal
  • Higher-Order Functions
  • Passing Along Arguments
  • JSON
  • Filtering an Array
  • Transforming with map
  • Summarizing with reduce
  • Composability
  • The Cost
  • Great-great-great-great-
  • Binding
  • Summary
  • Exercises
    • Flattening
    • Mother-Child Age Difference
    • Historical Life Expectancy
    • Every and Then Some

6 THE SECRET LIFE OF OBJECTS

  • History
  • Methods
  • Prototypes
  • Constructors
  • Overriding Derived Properties
  • Prototype Interference
  • Prototype-less Objects
  • Polymorphism
  • Laying Out a Table
  • Getters and Setters
  • Inheritance
  • The instanceof Operator
  • Summary
  • Exercises
    • A Vector Type
    • Another Cell
    • Sequence Interface

7 PROJECT: ELECTRONIC LIFE

  • Definition
  • Representing Space
  • A Critter’s Programming Interface
  • The World Object
  • this and Its Scope
  • Animating Life
  • It Moves
  • More Life-forms
  • A More Lifelike Simulation
  • Action Handlers
  • Populating the New World
  • Bringing the World to Life
  • Exercises
    • Artificial Stupidity
    • Predators

8 BUGS AND ERROR HANDLING

  • Programmer Mistakes
  • Strict Mode
  • Testing
  • Debugging
  • Error Propagation
  • Exceptions
  • Cleaning Up After Exceptions
  • Selective Catching
  • Assertions
  • Summary
  • Exercises
    • Retry
    • The Locked Box

9 REGULAR EXPRESSIONS

  • Creating a Regular Expression
  • Testing for Matches
  • Matching a Set of Characters
  • Repeating Parts of a Pattern
  • Grouping Subexpressions
  • Matches and Groups
  • The Date Type
  • Word and String Boundaries
  • Choice Patterns
  • The Mechanics of Matching
  • Backtracking
  • The replace Method
  • Greed
  • Dynamically Creating RegExp Objects
  • The search Method
  • The lastIndex Property
  • Looping over Matches
  • Parsing an INI File
  • International Characters
  • Summary
  • Exercises
    • Regexp Golf
    • Quoting Style
    • Numbers Again

10 MODULES

  • Why Modules Help
  • Namespacing
  • Reuse
  • Decoupling
  • Using Functions as Namespaces
  • Objects as Interfaces
  • Detaching from the Global Scope
  • Evaluating Data as Code
  • The require Function
  • Slow-Loading Modules
  • Interface Design
  • Predictability
  • Composability
  • Layered Interfaces
  • Summary
  • Exercises
    • Month Names
    • A Return to Electronic Life
    • Circular Dependencies

11 PROJECT: A PROGRAMMING LANGUAGE

  • Parsing
  • The Evaluator
  • Special Forms
  • The Environment
  • Functions
  • Compilation
  • Cheating
  • Exercises
    • Arrays
    • Closure
    • Comments
    • Fixing Scope

12 JAVASCRIPT AND THE BROWSER

  • Networks and the Internet
  • The Web
  • HTML
  • HTML and JavaScript
  • In the Sandbox
  • Compatibility and the Browser Wars

13 THE DOCUMENT OBJECT MODEL

  • Document Structure
  • Trees
  • The Standard
  • Moving Through the Tree
  • Finding Elements
  • Changing the Document
  • Creating Nodes
  • Attributes
  • Layout
  • Styling
  • Cascading Styles
  • Query Selectors
  • Positioning and Animating
  • Summary
    • Exercises
    • Build a Table
    • Elements by Tag Name
    • The Cat’s Hat

14 HANDLING EVENTS

  • Event Handlers
  • Events and DOM Nodes
  • Event Objects
  • Propagation
  • Default Actions
  • Key Events
  • Mouse Clicks
  • Mouse Motion
  • Scroll Events
  • Focus Events
  • Load Event
  • Script Execution Timeline
  • Setting Timers
  • Debouncing
  • Summary
  • Exercises
    • Censored Keyboard
    • Mouse Trail
    • Tabs

15 PROJECT: A PLATFORM GAME

  • The Game
  • The Technology
  • Levels
  • Reading a Level
  • Actors
  • Encapsulation as a Burden
  • Drawing
  • Motion and Collision
  • Actors and Actions
  • Tracking Keys
  • Running the Game
  • Exercises
    • Game Over
    • Pausing the Game

16 DRAWING ON CANVAS

  • SVG
  • The Canvas Element
  • Filling and Stroking
  • Paths
  • Curves
  • Drawing a Pie Chart
  • Text
  • Images
  • Transformation
  • Storing and Clearing Transformations
  • Back to the Game
  • Choosing a Graphics Interface
  • Summary
  • Exercises
    • Shapes
    • The Pie Chart
    • A Bouncing Ball
    • Precomputed Mirroring

17 HTTP

  • The Protocol
  • Browsers and HTTP
  • XMLHttpRequest
  • Sending a Request
  • Asynchronous Requests
  • Fetching XML Data
  • HTTP Sandboxing
  • Abstracting Requests
  • Promises
  • Appreciating HTTP
  • Security and HTTPS
  • Summary
  • Exercises
    • Content Negotiation
    • Waiting for Multiple Promises

18 FORMS AND FORM FIELDS

  • Fields
  • Focus
  • Disabled Fields
  • The Form as a Whole
  • Text Fields
  • Checkboxes and Radio Buttons
  • Select Fields
  • File Fields
  • Storing Data Client-Side
  • Summary
  • Exercises
    • A JavaScript Workbench
    • Autocompletion
    • Conway’s Game of Life

19 PROJECT: A PAINT PROGRAM

  • Implementation
  • Building the DOM
  • The Foundation
  • Tool Selection
  • Color and Brush Size
  • Saving
  • Loading Image Files
  • Finishing Up
  • Exercises
    • Rectangles
    • Color Picker
    • Flood Fill

20 NODE

  • Background
  • Asynchronicity
  • The node Command
  • Modules
  • Installing with NPM
  • The Filesystem Module
  • The HTTP Module
  • Streams
  • A Simple File Server
  • Error Handling
  • Summary
  • Exercises
    • Content Negotiation, Again
    • Fixing a Leak
    • Creating Directories
    • A Public Space on the Web

21 PROJECT: SKILL-SHARING WEBSITE

  • Design
  • Long Polling
  • HTTP Interface
  • The Server
  • Routing
  • Serving Files
  • Talks as Resources
  • Long-Polling Support
  • The Client
  • HTML
  • Starting up
  • Displaying Talks
  • Updating the Server
  • Noticing Changes
  • Exercises
    • Disk Persistence
    • Comment Field Resets
    • Better Templates
    • The Unscriptables

22 JAVASCRIPT AND PERFORMANCE

  • Staged Compilation
  • Graph Layout
  • Defining a Graph
  • A First Force-Directed Layout Function
  • Profiling
  • Function Inlining
  • Going Back to Old-school Loops
  • Avoiding Work
  • Creating Less Garbage
  • Garbage Collection
  • Writing to Objects
  • Dynamic Types
  • Summary
  • Exercises
    • Pathfinding
    • Timing
    • Optimizing