Skip to content
Advertisement

Tag: enums

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: export const enum Snack { Apple = 0, Banana = 1, Orange = 2, …

What is the preferred syntax for defining enums in JavaScript?

What is the preferred syntax for defining enums in JavaScript? Something like: Or is there a more preferable idiom? AdvertisementAnswer Since 1.8.5 it’s possible to seal and freeze the object, so define the above as: or and voila! JS enums. However, this doesn’t prevent you from assigning an undesired value to a variable, which is […]

Advertisement