Articles → JavaScript → Enums In JavascriptEnums In JavascriptEnum is a data type consists of set of named value. The main benefit of using enum in programming language is it makes the code simple and easy to maintain. Like all other languages JavaScript also supports enums.Syntax: - var variable_name = {enumerator_1:value, enumerator_2:value….}For example – If you are working on a tutorial website and the website contains 2 types of content then we can represent the content type with an enum in JavaScript var contentType = { Articles:0,InterviewQuestions:1 };The values can be accessed by contentType.Articles and contentType.InterviewQuestions. The first one will return the value 0 and the second one will return the value as false.Posted By - Karan Gupta Posted On - Monday, August 15, 2011 Query/Feedback Your Email Id Subject Query/Feedback Characters remaining 250
var variable_name = {enumerator_1:value, enumerator_2:value….}
var contentType = { Articles:0,InterviewQuestions:1 };
Query/Feedback