Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
Why can’t back ticks be used in JavaScript objects

Why are back ticks for object properties invalid syntax? For example, this is valid:

const test = {
  "test1": "test2"
}

So why can’t it have back ticks instead?

const test = {
  `test1`: "test2"
}
//throws unexpected token error

It would be really helpful if back ticks could be used like this, but we can’t. Is there a simple alternative, or maybe this works in some browsers?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need to put it into brackets like this because it's evaluated at runtime.

const test = {
  [`test1`]: "test2"
}

As @Amadan pointed out in the comment, you can use any expression as a property key by putting it into brackets.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can write like this:

const key = `test1`
const test = { [key]: 'test2' }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda