JavaScript object property names can be any string, including having hyphens in the name. However, object property names that are not valid JavaScript identifiers, can only be:

  1. Specified using quotes, and;
  2. Accessed using the bracket property accessor notation.

For example, the following is a valid property name:

const obj = { 'foo-bar': 123 };

console.log(obj['foo-bar']); // 123

You can even have hyphens at start or the end of the property name:

const cssVar = { '--dark-color': '#000' };

console.log(cssVar['--dark-color']); // '#000'