Summary
JavaScript is an asynchronous, event-driven, single-threaded language. Instead of hanging during a long-running operation to another resource, JavaScript does work on other operations if any work is pending. JavaScript accomplishes this with the event loop. The event loop is composed of the call stack, heap, event queue, and main event loop. These four components work together to schedule when JavaScript runs different parts of the code. To leverage JavaScript's asynchronous nature, we use callbacks or promises. Callbacks are simply functions passed as arguments into other functions. Promises are special classes with event handler functions. When an asynchronous operation finishes, the JavaScript engine runs the callback or calls the promise handler attached to that operation's complete event. This is asynchronous JavaScript in its simplest form.
In the next chapter, we will learn about the Document Object Model (DOM), the JavaScript event object, and the jQuery library.