How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 11-03-symbols-simulate-enums.
  3. Create a main.js file that defines a new object named LaunchSite , property values of the object should be local Symbols:
// main.js 
const LaunchSite = { 
  KENNEDY_SPACE_CENTER: Symbol('Kennedy Space Center'), 
  WHITE_SANDS: Symbol('White Sands Missile Range'), 
  BAIKONUR: Symbol('Baikonur Cosmodrome'), 
  BROGLIO: Symbol('Broglio Space Center'), 
  VIKRAM_SARABHAI: Symbol('Vikram Sarabhai Space Centre') 
}   
  1. Create a main function and compare the value of an enum entry to different values:
// main.js export function main() { console.log("Kennedy Space Center Site: ", LaunchSite.KENNEDY_SPACE_CENTER); console.log("Duplicate ...

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.