You are previewing Learning JavaScript, 3rd Edition.
O'Reilly logo
Learning JavaScript, 3rd Edition

Book Description

This is an exciting time to learn JavaScript. Now that the latest JavaScript specification—ECMAScript 6.0 (ES6)—has been finalized, learning how to develop high-quality applications with this language is easier and more satisfying than ever. This practical book takes programmers (amateurs and pros alike) on a no-nonsense tour of ES6, along with some related tools and techniques.

Table of Contents

  1. Preface
    1. A Brief History of JavaScript
    2. ES6
    3. Who This Book Is For
    4. What This Book Is Not
    5. Conventions Used in This Book
    6. Safari® Books Online
    7. How to Contact Us
    8. Acknowledgments
  2. 1. Your First Application
    1. Where to Start
    2. The Tools
    3. A Comment on Comments
    4. Getting Started
    5. The JavaScript Console
    6. jQuery
    7. Drawing Graphics Primitive
    8. Automating Repetitive Tasks
    9. Handling User Input
    10. Hello, World
  3. 2. JavaScript Development Tools
    1. Writing ES6 Today
    2. ES6 Features
      1. Installing Git
      2. The Terminal
      3. Your Project Root
      4. Version Control: Git
      5. Package Management: npm
      6. Build Tools: Gulp and Grunt
      7. Project Structure
    3. The Transcompilers
      1. Running Babel with Gulp
    4. Linting
    5. Conclusion
  4. 3. Literals, Variables, Constants, and Data Types
    1. Variables and Constants
    2. Variables or Constants: Which to Use?
    3. Identifier Names
    4. Literals
    5. Primitive Types and Objects
    6. Numbers
    7. Strings
      1. Escaping
    8. Special Characters
      1. Template Strings
      2. Multiline Strings
      3. Numbers as Strings
    9. Booleans
    10. Symbols
    11. null and undefined
    12. Objects
    13. Number, String, and Boolean Objects
    14. Arrays
    15. Trailing Commas in Objects and Arrays
    16. Dates
    17. Regular Expressions
    18. Maps and Sets
    19. Data Type Conversion
      1. Converting to Numbers
      2. Converting to String
      3. Converting to Boolean
    20. Conclusion
  5. 4. Control Flow
    1. A Control Flow Primer
      1. while Loops
      2. Block Statements
      3. Whitespace
      4. Helper Functions
      5. if…else Statement
      6. do…while Loop
      7. for Loop
      8. if Statement
      9. Putting It All Together
    2. Control Flow Statements in JavaScript
      1. Control Flow Exceptions
      2. Chaining if...else Statements
      3. Metasyntax
      4. Additional for Loop Patterns
      5. switch Statements
      6. for...in loop
      7. for...of loop
    3. Useful Control Flow Patterns
      1. Using continue to Reduce Conditional Nesting
      2. Using break or return to Avoid Unnecessary Computation
      3. Using Value of Index After Loop Completion
      4. Using Descending Indexes When Modifying Lists
    4. Conclusion
  6. 5. Expressions and Operators
    1. Operators
    2. Arithmetic Operators
    3. Operator Precedence
    4. Comparison Operators
    5. Comparing Numbers
    6. String Concatenation
    7. Logical Operators
      1. Truthy and Falsy Values
    8. AND, OR, and NOT
      1. Short-Circuit Evaluation
      2. Logical Operators with Nonboolean Operands
      3. Conditional Operator
      4. Comma Operator
    9. Grouping Operator
      1. Bitwise Operators
      2. typeof Operator
      3. void Operator
      4. Assignment Operators
    10. Destructuring Assignment
    11. Object and Array Operators
    12. Expressions in Template Strings
    13. Expressions and Control Flow Patterns
      1. Converting if...else Statements to Conditional Expressions
      2. Converting if Statements to Short-Circuited Logical OR Expressions
    14. Conclusion
  7. 6. Functions
    1. Return Values
    2. Calling Versus Referencing
    3. Function Arguments
      1. Do Arguments Make the Function?
      2. Destructuring Arguments
      3. Default Arguments
    4. Functions as Properties of Objects
    5. The this Keyword
    6. Function Expressions and Anonymous Functions
    7. Arrow Notation
    8. call, apply, and bind
    9. Conclusion
  8. 7. Scope
    1. Scope Versus Existence
    2. Lexical Versus Dynamic Scoping
    3. Global Scope
    4. Block Scope
    5. Variable Masking
    6. Functions, Closures, and Lexical Scope
    7. Immediately Invoked Function Expressions
    8. Function Scope and Hoisting
    9. Function Hoisting
    10. The Temporal Dead Zone
    11. Strict Mode
    12. Conclusion
  9. 8. Arrays and Array Processing
    1. A Review of Arrays
    2. Array Content Manipulation
      1. Adding or Removing Single Elements at the Beginning or End
      2. Adding Multiple Elements at the End
      3. Getting a Subarray
      4. Adding or Removing Elements at Any Position
      5. Cutting and Replacing Within an Array
      6. Filling an Array with a Specific Value
      7. Reversing and Sorting Arrays
    3. Array Searching
    4. The Fundamental Array Operations: map and filter
    5. Array Magic: reduce
    6. Array Methods and Deleted or Never-Defined Elements
    7. String Joining
    8. Conclusion
  10. 9. Objects and Object-Oriented Programming
    1. Property Enumeration
      1. for...in
      2. Object.keys
    2. Object-Oriented Programming
      1. Class and Instance Creation
      2. Dynamic Properties
      3. Classes Are Functions
      4. The Prototype
      5. Static Methods
      6. Inheritance
      7. Polymorphism
      8. Enumerating Object Properties, Revisited
      9. String Representation
    3. Multiple Inheritance, Mixins, and Interfaces
    4. Conclusion
  11. 10. Maps and Sets
    1. Maps
    2. Weak Maps
    3. Sets
    4. Weak Sets
    5. Breaking the Object Habit
  12. 11. Exceptions and Error Handling
    1. The Error Object
    2. Exception Handling with try and catch
    3. Throwing Errors
    4. Exception Handling and the Call Stack
    5. try...catch...finally
    6. Let Exceptions Be Exceptional
  13. 12. Iterators and Generators
    1. The Iteration Protocol
    2. Generators
      1. yield Expressions and Two-Way Communication
      2. Generators and return
    3. Conclusion
  14. 13. Functions and the Power of Abstract Thinking
    1. Functions as Subroutines
    2. Functions as Subroutines That Return a Value
    3. Functions as…Functions
    4. So What?
      1. Functions Are Objects
    5. IIFEs and Asynchronous Code
    6. Function Variables
      1. Functions in an Array
      2. Pass a Function into a Function
      3. Return a Function from a Function
    7. Recursion
    8. Conclusion
  15. 14. Asynchronous Programming
    1. The Analogy
    2. Callbacks
      1. setInterval and clearInterval
      2. Scope and Asynchronous Execution
      3. Error-First Callbacks
      4. Callback Hell
    3. Promises
      1. Creating Promises
      2. Using Promises
      3. Events
      4. Promise Chaining
      5. Preventing Unsettled Promises
    4. Generators
      1. One Step Forward and Two Steps Back?
      2. Don’t Write Your Own Generator Runner
      3. Exception Handling in Generator Runners
    5. Conclusion
  16. 15. Date and Time
    1. Dates, Time Zones, Timestamps, and the Unix Epoch
    2. Constructing Date Objects
    3. Moment.js
    4. A Practical Approach to Dates in JavaScript
    5. Constructing Dates
      1. Constructing Dates on the Server
      2. Constructing Dates in the Browser
    6. Transmitting Dates
    7. Displaying Dates
    8. Date Components
    9. Comparing Dates
    10. Date Arithmetic
    11. User-Friendly Relative Dates
    12. Conclusion
  17. 16. Math
    1. Formatting Numbers
      1. Fixed Decimals
      2. Exponential Notation
      3. Fixed Precision
      4. Different Bases
      5. Advanced Number Formatting
    2. Constants
    3. Algebraic Functions
      1. Exponentiation
      2. Logarithmic Functions
      3. Miscellaneous
      4. Pseudorandom Number Generation
    4. Trigonometric Functions
    5. Hyperbolic Functions
  18. 17. Regular Expressions
    1. Substring Matching and Replacing
    2. Constructing Regular Expressions
    3. Searching with Regular Expressions
    4. Replacing with Regular Expressions
    5. Input Consumption
    6. Alternation
    7. Matching HTML
    8. Character Sets
    9. Named Character Sets
    10. Repetition
    11. The Period Metacharacter and Escaping
      1. A True Wildcard
    12. Grouping
    13. Lazy Matches, Greedy Matches
    14. Backreferences
    15. Replacing Groups
    16. Function Replacements
    17. Anchoring
    18. Word Boundary Matching
    19. Lookaheads
    20. Constructing Regexes Dynamically
    21. Conclusion
  19. 18. JavaScript in the Browser
    1. ES5 or ES6?
    2. The Document Object Model
    3. Some Tree Terminology
    4. DOM “Get” Methods
    5. Querying DOM Elements
    6. Manipulating DOM Elements
    7. Creating New DOM Elements
    8. Styling Elements
    9. Data Attributes
    10. Events
      1. Event Capturing and Bubbling
      2. Event Categories
    11. Ajax
    12. Conclusion
  20. 19. jQuery
    1. The Almighty Dollar (Sign)
    2. Including jQuery
    3. Waiting for the DOM to Load
    4. jQuery-Wrapped DOM Elements
    5. Manipulating Elements
    6. Unwrapping jQuery Objects
    7. Ajax
    8. Conclusion
  21. 20. Node
    1. Node Fundamentals
    2. Modules
    3. Core Modules, File Modules, and npm Modules
    4. Customizing Modules with Function Modules
    5. Filesystem Access
    6. Process
    7. Operating System
    8. Child Processes
    9. Streams
    10. Web Servers
    11. Conclusion
  22. 21. Object Property Configuration and Proxies
    1. Accessor Properties: Getters and Setters
    2. Object Property Attributes
    3. Protecting Objects: Freezing, Sealing, and Preventing Extension
    4. Proxies
    5. Conclusion
  23. 22. Additional Resources
    1. Online Documentation
    2. Periodicals
    3. Blogs and Tutorials
    4. Stack Overflow
    5. Contributing to Open Source Projects
    6. Conclusion
  24. A. Reserved Words
  25. B. Operator Precedence
  26. Index