O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JavaScript: Best Practice

Book Description

There's no doubt that the JavaScript ecosystem changes fast. Not only are new tools and frameworks introduced and developed at a rapid rate, the language itself has undergone big changes with the introduction of ES2015 (aka ES6). Understandably, many articles have been written complaining about how difficult it is to learn modern JavaScript development these days. We're aiming to minimize that confusion with this set of books on modern JavaScript.

This book presents modern JavaScript best practice, utilizing the features now available in the language that enable you to write more powerful code that is clean, performant, maintainable, and resusable. It contains:

  • The Anatomy of a Modern JavaScript Application by James Kolce
  • Clean Code with ES6 Default Parameters & Property Shorthands by Moritz Kruger
  • JavaScript Performance Optimization Tips: An Overview by Ivan CuriC
  • JavaScript Design Patterns: The Singleton by Samier Saeed
  • JavaScript Object Creation: Patterns and Best Practices by Jeff Mott
  • Best Practices for Using Modern JavaScript Syntax by M. David Green
  • Flow Control in Modern JS: Callbacks to Promises to Async/Await by Craig Buckler
  • JavaScript's New Private Class Fields, and How to Use Them by Craig Buckler

This book is for all front-end developers who wish to improve their JavaScript skills. You'll need to be familiar with HTML and CSS and have a reasonable level of understanding of JavaScript in order to follow the discussion.

Table of Contents

  1. JavaScript: Best Practice
  2. Notice of Rights
  3. Notice of Liability
  4. Trademark Notice
  5. About SitePoint
  6. Preface
    1. Who Should Read This Book?
    2. Conventions Used
      1. Code Samples
      2. Tips, Notes, and Warnings
  7. Chapter 1: The Anatomy of a Modern JavaScript Application
    1. by James Kolce
    2. A Note About Node.js
    3. JavaScript ES2015+
      1. Declaring variables
      2. Arrow functions
      3. Improved Class syntax
      4. Promises / Async functions
      5. Modules
      6. Code linting
    4. Modular Code
      1. CommonJS modules
      2. ES2015 modules
    5. Package Management
    6. Build Tools
      1. Module bundling
      2. Transpilation
      3. Build systems & task runners
    7. Application Architecture
      1. Single Page Applications (SPAs)
      2. Universal / Isomorphic Applications
    8. Deployment
      1. Team development
    9. Conclusion
  8. Chapter 2: Clean Code with ES6 Default Parameters & Property Shorthands
    1. by Moritz Kröger
    2. ES6 Default Parameters
      1. A real-world example
    3. ES6 Property Shorthands
      1. Shorten Your API
    4. Conclusion
  9. Chapter 3: JavaScript Performance Optimization Tips: An Overview
    1. by Ivan Čurić
    2. Setting the Stage
    3. What Exactly is Performant JS Code?
      1. Respond
      2. Animate
      3. Idle work
      4. Load
    4. Context is Everything
    5. Parsing, Compiling and Executing
    6. Bundle Sizes are Everything
    7. Conclusion
  10. Chapter 4: JavaScript Design Patterns: The Singleton
    1. by Samier Saeed
    2. Explaining ES6
    3. What Is a Singleton
    4. The Old Way of Creating a Singleton in JavaScript
    5. The New Way(s)
    6. Conclusion
  11. Chapter 5:JavaScript Object Creation: Patterns and Best Practices
    1. by Jeff Mott
    2. Object Literals
    3. Factory Functions
    4. Prototype Chains
    5. ES5 Classes
    6. ES6 Classes
    7. Comparison
      1. Performance
      2. Features
    8. Conclusion
  12. Chapter 6: Best Practices for Using Modern JavaScript Syntax
    1. by M. David Green
    2. Something Solid to Cling To
    3. A Spoonful of Syntactic Sugar
    4. When Your const Isn’t Consistent
    5. Limiting the Scope of the Function
      1. Getting to Class on Time
      2. Pointed Differences with Arrow Functions
    6. Understand What You’re Getting
  13. Chapter 7: Flow Control in Modern JS: Callbacks to Promises to Async/Await
    1. by Craig Buckler
    2. Single-thread Processing
    3. Going Asynchronous with Callbacks
      1. Callback Hell
    4. Promises
      1. Asynchronous Chaining
      2. Multiple Asynchronous Calls with Promise.all()
      3. Multiple Asynchronous Calls with Promise.race()
      4. A Promising Future?
    5. Async/Await
      1. Promises, Promises
      2. Asynchronous Awaits in Synchronous Loops
      3. try/catch Ugliness
    6. JavaScript Journey
  14. Chapter 8: JavaScript’s New Private Class Fields, and How to Use Them
    1. by Craig Buckler
    2. ES6 Class Basics
    3. Getters and Setters
    4. Child or Sub-Classes
    5. Static Methods and Properties
    6. ESnext Class Fields
      1. Static Class Fields
      2. Private Class Fields
    7. Immediate Benefit: Cleaner React Code!
    8. Using Class Fields Today
    9. Class Fields: an Improvement?