Pages: 282 Published: April 2018 ISBN: 9781680502886
In Print
Simplifying JavaScript
Writing Modern JavaScript with ES5, ES6, and Beyond
by Joe Morgan
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 expressive. 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 reusable classes, to patterns for architecting large
applications creating applications that will last 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).
Production is complete. Now it’s on to layout and the printer.
2018/02/05
B2.0
*This release includes the final two chapters, Chapters 9 and 10. These chapters take you through accessing external data and project architecture.*The book is now content-complete and heading to production.
Tip 3. Isolate Information with Block Scoped Variables
Tip 4. Convert Variables to Readable Strings with Template
Literals
Manage Data Collections with Arrays
Tip 5. Create Flexible Collections with Arrays
Tip 6. Check Existence in an Array with Includes()
Tip 7. Mold Arrays with the Spread Operator
Tip 8. Avoid Push Mutations with the Spread Operator
Tip 9. Avoid Sort Confusion with the Spread Operator
Maximize Code Clarity with Special Collections
Tip 10. Use Objects for Static Key-Value Lookups 41
Tip 11. Create Objects Without Mutations Using Object.assign()
Tip 12. Update Information with Object Spread
excerpt
Tip 13. Update Key-Value Data Clearly with Maps
Tip 14. Iterate Over Key-Value Data with Map and the Spread
Operator
Tip 15. Create Maps Without Side Effects
Tip 16. Keep Unique Values with Set
Write Clear Conditionals
Tip 17. Shorten Conditionals with Falsy Values
Tip 18. Check Data Quickly with the Ternary Operator
Tip 19. Maximize Efficiency with Short Circuiting Simplify Loops
Tip 20. Simplify Looping with Arrow Functions
Tip 21. Write Shorter Loops with Array Methods
Tip 22. Create Arrays of a Similar Size with map()
Tip 23. Pull Out Subsets of Data with filter() and find()
Tip 24. Apply Consistent Actions with forEach()
Tip 25. Combine Methods with Chaining
Tip 26. Transform Array Data with reduce()
Tip 27. Reduce Loop Clutter with for…in and for…each
Clean Up Parameters and Return Statements
Tip 28. Create Default Parameters
Tip 29. Access Object Properties with Destructuring
Tip 30. Simplify Key-Value Assignment
Tip 31. Pass a Variable Number of Arguments with the Rest
Operator
Build Flexible Functions
Tip 32. Write Functions for Testability
Tip 33. Reduce Complexity with Arrow Functions
excerpt
Tip 34. Maintain Single Responsibility Parameters with Partially
Applied Functions
Tip 35. Combine Currying and Array Methods for Partial
Application
Tip 36. Prevent Context Confusion with Arrow Functions
Keep Interfaces Clear with Classes
Tip 37. Build Readable Classes
Tip 38. Share Methods with Inheritance
Tip 39. Extend Existing Prototypes with Class
Tip 40. Simplify Interfaces with get and set
Tip 41. Create Iterable Properties with Generators
excerpt
Tip 42. Resolve Context Problems with Bind()
Access External Data
Tip 43. Retrieve Data Asynchronously with Promises
Tip 44. Create Clean Functions with Async/Await
Tip 45. Make Simple AJAX Calls with Fetch
Tip 46. Maintain State Over Time with LocalStorage
Gather Related Files with Component Architecture
Tip 47. Isolate Functionality with Import and Export
Tip 48. Leverage Community Knowledge with npm
Tip 49. Build Applications with Component Architecture
Tip 50. Use Build Tools to Combine Components
Tip 51. Leverage CSS for Animations
Bibliography
Index
Author
Joe Morgan is a developer out of Lawrence, KS. Joe was born without
any code knowledge at all, and since then, he’s been trying to learn a
little more every day. A long-time JavaScript fan, he’s enjoying the
JavaScript renaissance that has made it more beautiful than ever. He
loves writing and speaking on JavaScript and craftsmanship.