Our enum type ServerState has an underlying integer type. The possible values for ServerState are defined as constants. By implementing the toString method, values of ServerState can be printed out or converted to strings.
To run the program, save the code in a JavaScript file (for example, enum_example.js) and run it using Node.js:
This example demonstrates how to implement and use an enum-like pattern in JavaScript, including type safety and state transition mechanisms.