concept union in category javascript

appears as: union, unions
The Joy of JavaScript

This is an excerpt from Manning's book The Joy of JavaScript.

Pattern matching is the perfect new feature to work with ADTs, especially with choice or union ADTs like Validation, Maybe, and Try because it allows an ADT to be deconstructed (which JavaScript already supports). Based on the ECMAScript specification for destructuring binding patterns (https://tc39.github.io/ecma262/#sec-destructuring-binding-patterns), this proposal enhances the existing ECMAScript 2015 destructuring feature with the ability to conditionally match on the duck-typed structure of an object. Basically, it’s like combining destructuring with a sophisticated switch statement, and works great to inspect the contents of an ADT:

You just learned about types with classes, interfaces, objects, functions, generics, and unions. In my experience these are the ones that occur most often in day-to-day code and are likely to be the first included in any future proposal. There are many other type annotations that you can use. I encourage you to read about it on your own if you find this technology interesting. Here’s a good article to get you started (http://code.sgo.to/proposal-optional-types/). Knowing what signatures are and what they mean will still be important in order to communicate efficiently about how functions are used and compose with the rest of your code. The good news is that it’s not an all or nothing route. You can start to add types progressively as you learn and become more comfortable with them.