Skip to content
Home Tutorials Roadmaps Courses
Log in Join free
TypeScript Intermediate FREE

Enums

Lesson 2 of 17 Intermediate Interactive

Enums define a set of named constants. Numeric enums auto-increment.

Syntax

TYPESCRIPT
enum Direction {
    Up,
    Down,
    Left,
    Right
}

enum Status {
    Active = "ACTIVE",
    Inactive = "INACTIVE"
}
TypeScript Enums
TYPESCRIPT
enum Status {
    Active = "ACTIVE",
    Inactive = "INACTIVE",
    Pending = "PENDING"
}

enum Color {
    Red = 0,
    Green = 1,
    Blue = 2
}

let userStatus: Status = Status.Active;
console.log(userStatus);

let primary: Color = Color.Red;
console.log(Color[primary]);

Practice

1
Exercise

Practice this concept.

Answer
Write the code as shown above.

Quick Quiz

1

What did you learn?

This covers the basics.

Interview Questions

It is a fundamental TypeScript feature.