Answers for "enum in javascript es6"

2

js enum

const daysEnum = Object.freeze({
  monday: 0,
  tuesday: 1,
  wednesday: 2,
  thursday: 3,
  friday: 4,
  saturday: 5,
  sunday: 6
});
Posted by: Guest on August-02-2021
18

javascript enum

const seasons = {
  SUMMER: {
    BEGINNING: "summer.beginning",
    ENDING: "summer.ending"
  },
  WINTER: "winter",
  SPRING: "spring",
  AUTUMN: "autumn"
};

let season = seasons.SUMMER.BEGINNING;

if (!season) {
  throw new Error("Season is not defined");
}

switch (season) {
  case seasons.SUMMER.BEGINNING:
  // Do something for summer beginning
  case seasons.SUMMER.ENDING:
  // Do something for summer ending
  case seasons.SUMMER:
  // This will work if season = seasons.SUMMER
  // Do something for summer (generic)
  case seasons.WINTER:
  //Do something for winter
  case seasons.SPRING:
  //Do something for spring
  case seasons.AUTUMN:
  //Do something for autumn
}
Posted by: Guest on May-06-2020
7

enum javascript

const DaysEnum = {"monday":1, "tuesday":2, "wednesday":3, ...}
Object.freeze(DaysEnum)
Posted by: Guest on October-04-2020
0

enum in javascript es6

const daysEnum = Object.freeze({
  monday: Symbol(0),
  tuesday: Symbol(1),
  wednesday: Symbol(2),
  thursday: Symbol(3),
  friday: Symbol(4),
  saturday: Symbol(5),
  sunday: Symbol(6)
});
Posted by: Guest on August-31-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language