
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Explain Enumerated Types in JavaScript.
JavaScript doesn’t support Enums out of the box. The only way to have enums in javaScript is to implement them using objects.
Following is the code showing enumerated types in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } </style> </head> <body> <h1>Enumerated Types in JavaScript</h1> <div class="result"></div> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to get the color values</h3> <script> let resEle = document.querySelector(".result"); let color = { orange: 1, red: 2, green: 3, blue: 4, pink: 5, }; document.querySelector(".Btn").addEventListener("click", () => { resEle.innerHTML += "color.orange = " + color.orange + "<br>"; resEle.innerHTML += "color.red = " + color.red + "<br>"; resEle.innerHTML += "color.green = " + color.green + "<br>"; resEle.innerHTML += "color.blue = " + color.blue + "<br>"; resEle.innerHTML += "color.pink = " + color.pink + "<br>"; }); </script> </body> </html>
Output
The above code will produce the following output −
On clicking the ‘CLICK HERE’ button −
- Related Articles
- Enumerated Types or Enums in C++
- What are enumerated data types in C++?
- What are Enumerated Constants in C++?
- What is enumerated data type in C language?
- How to define an enumerated type (enum) in C++?
- Explain the Tuple Types in TypeScript
- Explain and contrast value types and reference types in C#
- Explain types of combustion?
- Explain the custom value types in .NET
- Explain Merger and its types
- Explain acquisition and its types
- Explain types of osmotic solutions.
- Explain polygon and its types.
- Explain the types of crops.
- Explain the types of fractions.

Advertisements