Introduction
You have already covered the use of functions in TypeScript in Chapter 3, Functions. This chapter will introduce you to higher-order functions in TypeScript. Hitherto, with all the functions that you have used in this book, you either passed parameters or arguments into them. However, JavaScript and, by extension, TypeScript, has many ways of composing and writing code. In this chapter, we'll explore one such pattern – higher-order functions/callbacks (hereinafter called HOCs) are functions that either take in another function as an argument or return a function (or both).
Additionally, this chapter also explores the concept of callbacks. Callbacks are required in Node.js, as well as in other JavaScript runtimes, since the language is single-threaded and runs in an event loop, and so, in order to not hold up the main thread, we let other code run, and when needed it will call our code back. This chapter will also touch upon "callback hell" and...