ES6 safe to use static class variable as key for Map?

Viewed 825

In babel-preset-stage-0, we can declare static class variable as follow:

class Constants {
  static COUNTRY = Object.freeze({
      NAME: 'Germany',
      DESCRIPTION: 'placeholder',
  })
}

Is it safe to use Constants.COUNTRY as the key for a ES6 Map or Set?

eg.

const map = new Map();
map.add(Constants.COUNTRY, something);

Is it guaranteed that map.get(Constants.COUNTRY) will always return something?

Is the performance as good as using strings as key? Is it safe to use Constants.COUNTRY as eventKey (bootstrap component attribute) for NavItem too?

Is it also more appropriate to declare it as a variable instead of a class? i.e.

const Constants = Object.freeze({
  COUNTRY: Object.freeze({
      NAME: 'Germany',
      DESCRIPTION: 'placeholder',
  })
}) 
2 Answers
Related