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

261
Views
Pasar el valor de las variables externas en una plantilla etiquetada

tag es una función que acepta una cadena de plantilla:

 function tag(strings) { console.log(strings.raw); } tag`Output something`

Funciona bien. Ahora el problema es que tengo una variable externa y quiero pasar el valor de la variable a la cadena de la plantilla, algo como esto:

 function tag(strings) { console.log(strings.raw); } const key = "a" tag`The value of key: ${key}` // I need it to output "The value of key: a", but the actual output is "The value of key: "

No funciona como se esperaba porque javascript cree que key es uno de los parámetros de la tag . ¿Cómo resolver este problema?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Necesita tener otro parámetro que acepte el valor clave.

 function tag( strings, key ) { console.log(strings[0] + key); } const key = "a" tag`The value of key: ${key}`
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!