diff --git a/notes/callbacks/callbacks.md b/notes/callbacks/callbacks.md old mode 100644 new mode 100755 index 70dae7e957b19cbd03d16d1c147dba4375f31b70..11fbca38704260a29be65b8ae1b8762a98337138 --- a/notes/callbacks/callbacks.md +++ b/notes/callbacks/callbacks.md @@ -134,7 +134,7 @@ setTimeout(() => { console.log('3 seconds have passed') }, 3000) ``` -The fact that `setTimeout()` is asynchronous means it returns immediately, without witing for the time interval. +The fact that `setTimeout()` is asynchronous means it returns immediately, without waiting for the time interval. For example, the following code displays `Timeout started` immediately and `Timeout ended` after 1 second: ```js setTimeout(() => { @@ -161,7 +161,7 @@ In general, this requires us to create the next asynchronous event *inside* the As a concrete example, let's simulate a "random walk" on a grid. At each step, we randomly move left, right, up, or down, and we count the total number of times we have visited each grid square. -To run an asynchronous action after another one finshes, we *nest it inside the previous callback*. +To run an asynchronous action after another one finishes, we *nest it inside the previous callback*. Here is a [first attempt](walk1.html) that only moves 3 times. ```js // ... (the full code is at the link above) @@ -226,7 +226,7 @@ walkFrom({row: Math.floor(SIZE / 2), col: Math.floor(SIZE / 2)}) We have seen two examples of asynchronous standard library functions in JavaScript: handling user input and waiting for time. With both of them, we define a function that we want to get called when something happens. -This structure is common to any asynchronous function; the function passed in to run when it finishes is refered to as the "callback function". +This structure is common to any asynchronous function; the function passed in to run when it finishes is referred to as the "callback function". It is up to the browser (or Node.js) to ensure that the callbacks we provide get called at the right times. We have also looked at some of the primary ways to combine asynchronous actions.