Working with Enums in TypeScript

Explore how TypeScript enums can be used to represent a set of named constants, making your code more readable and self-explanatory.

Working with Enums in TypeScript
Photo by Glenn Carstens-Peters / Unsplash

Explore how TypeScript enums can be used to represent a set of named constants, making your code more readable and self-explanatory.

enum Color {
  Red,
  Green,
  Blue,
}

const selectedColor: Color = Color.Red;

if (selectedColor === Color.Red) {
  console.log("Selected color is Red");
}