Safer JavaScript with the Maybe Type (series)

2 min read

Five years ago, I published a course on egghead.io called Safer JavaScript with the Maybe Type. In this series of articles, I'm going to cover that course in written form for those who prefer written content over video, do not have an egghead.io membership (you really should consider one though, just a ton of value to be had there), or for those who would like to read the words and watch the videos.

If you're unfamiliar with the Maybe type, it is a data type (an ADT or Algebraic Data Type) that wraps values and makes it safe to operate on a value without having to scatter conditionals throughout your code.

When values have the potential to change types or to end up as null or undefined, that can lead to runtime errors in our code or bizarre bugs that take forever to track down thanks to type coercion. To battle this, we end up with code that is littered with conditionals for null or undefined values and type checks, making the core logic harder to read and refactor later.

The Maybe encapsulates the type checking and guards against missing values for us. With Maybe in our tool belt, we can keep our functions free of all the guardrails, outsource that work to the Maybe and keep our business logic free of all the clutter.

You can follow along from this article, as I will update it with lists as each new entry in the series is published.