JavaScript does not have built-in support for enum
types like some other programming languages (e.g., TypeScript, C++). However, you can simulate enums
in JavaScript using objects or const
variables.
Example using an object:
const Colors = {
RED: 'red',
GREEN: 'green',
BLUE: 'blue'
};
console.log(Colors.RED); // 'red'
Alternatively, TypeScript provides a native enum
feature.
Tags: intermediate, JavaScript, features
URL: https://www.tiktok.com/@jsmentoring/photo/7464749346089749792