Rediscovering JavaScript

Book description

JavaScript is no longer to be feared or loathed - the world's most popular and ubiquitous language has evolved into a respectable language. Whether you're writing frontend applications or server side code, the phenomenal features from ES6 and beyond - like the rest operator, generators, destructuring, object literals, arrow functions, modern classes, promises, async, and metaprogramming capabilities - will get you excited and eager to program with JavaScript. You've found the right book to get started quickly and dive deep into the essence of modern JavaScript. Learn practical tips to apply the elegant parts of the language and the gotchas to avoid.

JavaScript is a black swan that no one, including the author of the language, thought would become a popular and ubiquitous language. Not long ago, it was the most hated and feared language you could use to program the web. JavaScript ES6 and beyond has gone through a significant makeover. Troublesome features have been replaced with better, elegant, more reliable alternatives. This book includes many practical examples and exercises to help you learn in depth. It will not bore you with idiosyncrasies and arcane details intended for bad interview questions. Instead, it takes you into key features that you can readily use in your day-to-day projects.

Whether you program the frontend or the server side, you can now write concise, elegant, and expressive JavaScript with newer features like default parameters, template literals, rest and spread operators, destructuring, arrow functions, and generators. Take it up a notch with features like infinite series, promises, async, and metaprogramming to create flexible, powerful, and extensible libraries. While the evolved features of the language will draw you in, the hundreds of examples in this book will pin the concepts down, for you to use on your projects. Take command of modern JavaScript and unlock your potential to create powerful applications.

What You Need:

To try out the examples in the book you will need a computer with Node.js, a text editor, and a browser like Chrome installed in it.

Publisher resources

View/Submit Errata

Table of contents

  1.  Acknowledgments
  2.  Introduction
    1. How to Run Modern JavaScript
    2. What’s in This Book?
    3. Who Is This Book For?
    4. Online Resources
  3. Part I. The Safe Alternatives
    1. 1. JavaScript Gotchas
      1. Be Careful Where You Break Lines
      2. Use === Instead of ==
      3. Declare Before Use
      4. Stay One Step Ahead
      5. Wrapping Up
    2. 2. Variables and Constants
      1. Out with var
      2. In with let
      3. Perils of Mutability
      4. const
      5. Safer Code with let and const
      6. Prefer const over let
      7. Wrapping Up
    3. 3. Working with Function Arguments
      1. The Power and Perils of arguments
      2. Using the Rest Parameter
      3. The Spread Operator
      4. Defining Default Values for Parameters
      5. Wrapping Up
  4. Part II. Nice Additions
    1. 4. Iterators and Symbols
      1. The Convenience of Enhanced for
      2. Symbol—A New Primitive Type
      3. Using Custom Iterators and Generators
      4. Creating Infinite Iterators
      5. Wrapping Up
    2. 5. Arrow Functions and Functional Style
      1. From Anonymous to Arrow Functions
      2. Anonymous vs. Arrow Functions
      3. Limitations of Arrow Functions
      4. When to Use Arrow Functions
      5. Arrow Functions and Functional Style
      6. Wrapping Up
    3. 6. Literals and Destructuring
      1. Using Template Literals
      2. Multiline Strings
      3. Tagged Template
      4. Enhanced Object Literals
      5. Destructuring
      6. Wrapping Up
  5. Part III. OO and Modular Code
    1. 7. Working with Classes
      1. Creating a Class
      2. Implementing a Constructor
      3. Defining a Method
      4. Defining Computed Members
      5. Creating Properties
      6. Defining Class Members
      7. Class Expressions
      8. New Built-in Classes: Set, Map, WeakSet, and WeakMap
      9. Wrapping Up
    2. 8. Using Inheritance
      1. Understanding Prototypal Inheritance
      2. Inheriting from a Class
      3. Managing Instance Types with species
      4. Wrapping Up
    3. 9. Using Modules
      1. Creating a Module
      2. Exporting from a Module
      3. Importing from a Module
      4. Wrapping Up
  6. Part IV. Going Meta
    1. 10. Keeping Your Promises
      1. No Thanks to Callback Hell
      2. Promises to the Rescue
      3. Ways to Create a Promise
      4. Chaining Promises
      5. Working with Multiple Promises
      6. Async and Await
      7. Wrapping Up
    2. 11. Exploring Metaprogramming
      1. The Power and Perils of Metaprogramming
      2. Dynamic Access
      3. Member Injection
      4. Wrapping Up
    3. 12. Deep Dive into Metaprogramming
      1. Purpose of Reflect
      2. Metaprogramming with Proxy
      3. Synthesizing Members with Proxy
      4. Using Decorators
      5. Wrapping Up
  7. A1. Answers to Exercises
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
  8. A2. Web Resources
  9.  Bibliography

Product information

  • Title: Rediscovering JavaScript
  • Author(s): Venkat Subramaniam
  • Release date: June 2018
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781680505467