So What? 187
IIFEs and Asynchronous Code 189
Pass a Function into a Function 194
Return a Function from a Function 195
Recursion 196
Conclusion 197
14.
The Analogy 200
Callbacks 200
setInterval and clearInterval 201
Scope and Asynchronous Execution 202
Callback Hell 204
Promises 205
Using Promises 206
Events 208
Promise Chaining 210
Preventing Unsettled Promises 211
Generators 212
One Step Forward and Two Steps Back? 215
Don’t Write Your Own Generator Runner 216
Exception Handling in Generator Runners 216
Conclusion 217
15.
Dates, Time Zones, Timestamps, and the Unix Epoch 219
Moment.js 221
A Practical Approach to Dates in JavaScript 222
Constructing Dates on the Server 222
Constructing Dates in the Browser 223
Displaying Dates 224
Date Components 225
Comparing Dates 226
x | Table of Contents