Using Symbol to simulate enums

We've seen how to create Symbol that can be accessed globally, and those that can't be accessed outside of their initial context. Now, we'll see how to use them to create something that wasn't really possible in earlier versions of JavaScript.

In this recipe, we'll use local Symbol to simulate a type that is available in many other languages, enums.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.