You may have heard of Algebraic Data Types (ADT’s) before but didn’t understand how they can be applied to everyday code - so this article will provide some examples and explanations of why you should start using them.
Before we get into ADT’s, let’s go over the foundation of what ADT’s are made of.
Basic Types
In Javascript, you can not declare a type that prevents other types from being assigned to it. The below example we see that anything can be assigned to the language variable. We can assign a number or a boolean or an object to it if we later wanted, but that may cause bugs in the future if we were not expecting the variable type to be something other than a string.