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.

Author Ethan Brown (Web Development with Node and Express) not only guides you through simple and straightforward topics (variables, control flow, arrays), but also covers complex concepts such as functional and asynchronous programming. You’ll learn how to create powerful and responsive web applications on the client, or with Node.js on the server.

  • Use ES6 today and transcompile code to portable ES5
  • Translate data into a format that JavaScript can use
  • Understand the basic usage and mechanics of JavaScript functions
  • Explore objects and object-oriented programming
  • Tackle new concepts such as iterators, generators, and proxies
  • Grasp the complexities of asynchronous programming
  • Work with the Document Object Model for browser-based apps
  • Learn Node.js fundamentals for developing server-side applications

Publisher resources

View/Submit Errata

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. O’Reilly Safari
    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. Drawing Graphics Primitives
    7. Automating Repetitive Tasks
    8. Handling User Input
    9. Hello, World
  3. 2. JavaScript Development
    1. Prerequisites
      1. Your Project Root
    2. What Are You Trying to Do?
    3. Node Applications
      1. Installing Node
      2. Running JavaScript Programs with Node
      3. Package Management: npm
    4. Web Applications
    5. Linting
    6. 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. The Document Object Model
    2. Some Tree Terminology
    3. DOM “Get” Methods
    4. Querying DOM Elements
    5. Manipulating DOM Elements
    6. Creating New DOM Elements
    7. Styling Elements
    8. Data Attributes
    9. Events
      1. Event Capturing and Bubbling
      2. Event Categories
    10. Ajax
    11. Conclusion
  20. 19. 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
  21. 20. 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
  22. 21. Additional Resources
    1. Online Documentation
    2. Periodicals
    3. Blogs and Tutorials
    4. Stack Overflow
    5. Contributing to Open Source Projects
    6. Conclusion
  23. A. The Terminal
  24. B. Version Control with Git
    1. Installing Git
    2. Using Git
  25. C. Reserved Words
  26. D. Operator Precedence
  27. Index

Product information

  • Title: Learning JavaScript, 3rd Edition
  • Author(s): Ethan Brown
  • Release date: February 2016
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491914915