Open In App

Explain the concept of enums in TypeScript ?

Last Updated : 23 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Enum in TypeScript is a shorthand used for the enumerations. Enum is a way of defining multiple related named constants at the same place in the form of a collection which can be later accessed and assigned to other variables in the code. By default, the enums are assigned with number type values starting from 0. You can also assign them with the string values using the assignment operator(=). It helps to enhance the code readability and maintainability by defining meaningful identifiers for the magic strings and the numbers.

Syntax:

enum enumName {
// Assigned with default number value 0
property1,
// Assigned with the given string value
property2 = "stringValue",
}

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads