Simplifying JavaScript

Book description

The best modern JavaScript is simple, readable, and predictable. Learn to write modern JavaScript not by memorizing a list of new syntax, but with practical examples of how syntax changes can make code more expressive. Starting from variable declarations that communicate intention clearly, see how modern principles can improve all parts of code. Incorporate ideas with curried functions, array methods, classes, and more to create code that does more with less while yielding fewer bugs.

It's time to write JavaScript code that's clean and exprssive. Modern JavaScript is simpler and more predictable and readable than ever. Discover how to write better code with clear examples using principles that show how updated syntax can make code better with fewer bugs.

Starting from the ground up, learn new syntax (or how to reuse older syntax) to transform code from clunky bug-susceptible scripts to clear and elegant programs that are easy to read and easy to extend.

Create a foundation for readable code with simple variable declarations that reduce side effects and subtle bugs. Select collections with clear goals instead of defaulting to objects or arrays. See how to simplify iterations from complex loops to single line array methods. Master techniques for writing flexible and solid code ranging from high-order functions, to reusableclasses, to patterns for architecting large applications creating applications that will last while through rounds of refactoring and changing requirements.

The best part is there's no need to read this book straight through. Jump around and incorporate new functionality at will. Most importantly, understand not just what the new syntax is, but when and how to use it. Start writing better code from the first page.

What You Need:

For the best experience, have the latest version of Node installed (at least version 7). You can test most examples in the console of Chrome or other modern web browser. If you'd like to run the tests, you'll also need to install the latest version of Node Package Manager (npm).

Publisher resources

View/Submit Errata

Table of contents

  1.  Introduction
    1. How To Use This Book
    2. Whom This Book Is For
    3. Online Resources
    4. Acknowledgments
  2. 1. Signal Intention with Variable Assignment
    1. Tip 1. Signal Unchanging Values with const
    2. Tip 2. Reduce Scope Conflicts with let and const
    3. Tip 3. Isolate Information with Block Scoped Variables
    4. Tip 4. Convert Variables to Readable Strings with Template Literals
  3. 2. Manage Data Collections with Arrays
    1. Tip 5. Create Flexible Collections with Arrays
    2. Tip 6. Check Existence in an Array with Includes()
    3. Tip 7. Mold Arrays with the Spread Operator
    4. Tip 8. Avoid Push Mutations with the Spread Operator
    5. Tip 9. Avoid Sort Confusion with the Spread Operator
  4. 3. Maximize Code Clarity with Special Collections
    1. Tip 10. Use Objects for Static Key-Value Lookups
    2. Tip 11. Create Objects Without Mutations Using Object.assign()
    3. Tip 12. Update Information with Object Spread
    4. Tip 13. Update Key-Value Data Clearly with Maps
    5. Tip 14. Iterate Over Key-Value Data with Map and the Spread Operator
    6. Tip 15. Create Maps Without Side Effects
    7. Tip 16. Keep Unique Values with Set
  5. 4. Write Clear Conditionals
    1. Tip 17. Shorten Conditionals with Falsy Values
    2. Tip 18. Check Data Quickly with the Ternary Operator
    3. Tip 19. Maximize Efficiency with Short Circuiting
  6. 5. Simplify Loops
    1. Tip 20. Simplify Looping with Arrow Functions
    2. Tip 21. Write Shorter Loops with Array Methods
    3. Tip 22. Create Arrays of a Similar Size with map()
    4. Tip 23. Pull Out Subsets of Data with filter() and find()
    5. Tip 24. Apply Consistent Actions with forEach()
    6. Tip 25. Combine Methods with Chaining
    7. Tip 26. Transform Array Data with reduce()
    8. Tip 27. Reduce Loop Clutter with for...in and for...each
  7. 6. Clean Up Parameters and Return Statements
    1. Tip 28. Create Default Parameters
    2. Tip 29. Access Object Properties with Destructuring
    3. Tip 30. Simplify Key-Value Assignment
    4. Tip 31. Pass a Variable Number of Arguments with the Rest Operator
  8. 7. Build Flexible Functions
    1. Tip 32. Write Functions for Testability
    2. Tip 33. Reduce Complexity with Arrow Functions
    3. Tip 34. Maintain Single Responsibility Parameters with Partially Applied Functions
    4. Tip 35. Combine Currying and Array Methods for Partial Application
    5. Tip 36. Prevent Context Confusion with Arrow Functions
  9. 8. Keep Interfaces Clear with Classes
    1. Tip 37. Build Readable Classes
    2. Tip 38. Share Methods with Inheritance
    3. Tip 39. Extend Existing Prototypes with Class
    4. Tip 40. Simplify Interfaces with get and set
    5. Tip 41. Create Iterable Properties with Generators
    6. Tip 42. Resolve Context Problems with Bind()
  10. 9. Access External Data
    1. Tip 43. Retrieve Data Asynchronously with Promises
    2. Tip 44. Create Clean Functions with Async/Await
    3. Tip 45. Make Simple AJAX Calls with Fetch
    4. Tip 46. Maintain State Over Time with LocalStorage
  11. 10. Gather Related Files with Component Architecture
    1. Tip 47. Isolate Functionality with Import and Export
    2. Tip 48. Leverage Community Knowledge with npm
    3. Tip 49. Build Applications with Component Architecture
    4. Tip 50. Use Build Tools to Combine Components
    5. Tip 51. Leverage CSS for Animations
  12.  Bibliography

Product information

  • Title: Simplifying JavaScript
  • Author(s): Joe Morgan
  • Release date: April 2018
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781680502886