Monads

Learn about monads and their usage with the help of coding examples.

How can we avoid exceptions? How will we handle error cases without them? If Promises aren’t ideal for asynchronous behavior, what should we use instead? Enter the dreaded monads!

What are monads?

Many articles explain monads, some from their mathematical beginnings, others using a broad range of examples. Here, it might suffice to compare them to a container. We have a certain value (a string, a number, or an object), and we put it inside that container. In several functional languages, putting the value inside the monad is called return. But, because return is a keyword in JavaScript, we’ll find various other words for it, like of.

Get hands-on with 1200+ tech skills courses.