Skip to content

Latest commit

 

History

History
20 lines (14 loc) · 685 Bytes

make-enum-like-structure.md

File metadata and controls

20 lines (14 loc) · 685 Bytes

Make an enum-like structure

Enums help document intent. To create an enum-like structure in JavaScript, you can use the Object.freeze method.

Example:

const COLORS = {
	red: "#CE0C0C", 
	green: "#00F0B5", 
	blue: "#26547C"
};

Object.freeze(COLORS);

console.log(COLORS.red); // #CE0C0C

See this discussion on Stack Overflow. For more discussion on Enums, see this thread. TypeScript supports Enums natively.