Chrome does not detect "$ {}"

1

I'm starting in JavaScript and I saw that now to concatenate strings you can use ${} , the issue is when you use it Chrome does not detect it:

 var nicolas ={
  nombre :"Nicolas",
  apellido :"Gigena",
  edad : 19
}

var pepe ={
  nombre :"Pepe",
  apellido:"Lil",
  edad:20
}

function imprimirNombre(persona){
  var {nombre, edad } = persona
  console.log("mi nombre es ${nombre} y tengo ${edad}")
}

imprimirNombre(nicolas)
imprimirNombre(pepe)

    
asked by nicolas gigena 07.09.2018 в 03:35
source

3 answers

6

When you use interpolation in Javascript you need to use '' instead of "" or ''.

console.log('mi nombre es ${nombre} y tengo ${edad}');

Here you can see more information .

    
answered by 07.09.2018 в 04:06
5

Try the following:

var nicolas ={
  nombre :"Nicolas",
  apellido :"Gigena",
  edad : 19
}

var pepe ={
  nombre :"Pepe",
  apellido:"Lil",
  edad:20
}

function imprimirNombre(persona){
  var {nombre, edad } = persona
  console.log('mi nombre es ${nombre} y tengo ${edad}')
}

imprimirNombre(nicolas)
imprimirNombre(pepe)

In JavaScript you can use the syntax ${} only when you declare the string with inverted quotes.

On keyboards with Latam distribution (Latin America):

alt gr + } = '

You can read a little more about strings in JavaScript here .

    
answered by 07.09.2018 в 04:04
0

Maybe you're looking for this

var nicolas ={
  nombre :"Nicolas",
  apellido :"Gigena",
  edad : 19
}

var pepe ={
  nombre :"Pepe",
  apellido:"Lil",
  edad:20
}

function imprimirNombre(persona){
  var {nombre, edad } = persona
  console.log("mi nombre es "+persona.nombre+" y tengo "+persona.edad)
}

imprimirNombre(nicolas)
imprimirNombre(pepe)

Command to call the variable using variable persona.nombre as if it were a JSON

Greetings:)

    
answered by 07.09.2018 в 03:47