Skip to content

Tag: enums

Enums in Javascript with ES6

I’m rebuilding an old Java project in Javascript, and realized that there’s no good way to do enums in JS. The best I can come up with is: The const keeps Colors from being reassigned, and freezing it prevents mutating the keys and values. I’m using Symbols so that Colors.RED is not equal to…

const enum in Typescript

I have a React application that is using Typescript. Right now I’m running into an issue with const enum. Here’s my enum: The service I’m trying to match up to isn’t returning the value, but the index of the item within the enum. So, for instance, if the user is set to snack on an appl…