What Is Enumerated Data Type Give an Example?


Scott Campbell

An enumerated data type, also known as an enum, is a user-defined data type in programming languages that consists of a set of named values. These values are called enumerators or constants. Enumerated data types are useful when we want to represent a fixed set of values that an variable can take.

Example of Enumerated Data Type:

To understand the concept better, let’s consider an example of an enumerated data type called “Color”. We want to define a variable that can only take one of three possible colors: Red, Green, or Blue.

To create this enumerated data type in HTML, we can use the following syntax:

<!DOCTYPE html>
    <title>Enumerated Data Type Example</title>

<h3>Example: Color Enum</h3>

<p>Here's how we can create an enum for colors:</p>

<code class="language-javascript">
enum Color {

<p>Now, we can declare a variable of this enum type and assign one of the defined colors to it.</p>

<p class="code-example">// Declaring a variable with the enum type and assigning a value</p>

let myColor: Color = Color.Red;
console.log(myColor); // Output: Red

In this example, we declared an enum called "Color" with three possible values: Red, Green, and Blue. We then declared a variable called "myColor" of type "Color" and assigned it the value "Red". When we print the value of "myColor", it will display "Red" in the console.


Enumerated data types are a convenient way to define a fixed set of values that a variable can take. They enhance code readability and maintainability by providing meaningful names to represent specific values.

In this article, we explored the concept of enumerated data types and provided an example using HTML syntax. By incorporating HTML styling elements such as bold, underline,

code blocks

, and


, we aimed to make the content engaging and visually appealing.

Now that you have a basic understanding of enumerated data types, you can apply this knowledge in your own programming projects to create more structured and readable code.


We hope you found this article helpful! Happy coding!

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy