Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
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 answers
Answer question

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 Report

0

You can write like this:

const key = `test1`
const test = { [key]: 'test2' }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!