SyntaxError: unexpected token: string literal -Javascript [closed]

0

I'm having this error in the following function:

function formaQueryConta(cpf){

        var numConta= jsonDtContasCliente[(document.getElementById("listaContas").value)-1];
        console.log(typeof(cpf)); //Diz que é String
        console.log(typeof(numConta)); //Diz que é String
        var parms = "&cpf="+cpf"&conta="+numConta; //O ERRO É APONTADO NESTA LINHA
        ajaxCall("Persistencia.php?action=buscaConta" +parms, formaCanvas);

}

I did not find anything on the Stack to help me. Any light?

    
asked by anonymous 02.06.2018 / 12:02

1 answer

2

+ is missing in concatenation:

var parms = "&cpf="+cpf"&conta="+numConta; //O ERRO É APONTADO NESTA LINHA
//                     ^---aqui
  

I did not find anything on the Stack to help me

This is normal, as this error can be for a variety of reasons and is more or less generic. It simply states that when you were building the string you found something you were not expecting, in this case " .

What I advise for the next few times and try to read the line calmly and pay attention to every caratere.

A common alternative nowadays in ES6 is to use template literals , which works as interpolation and which I personally find more readable. In that case it would look like this:

var parms = '&cpf=${cpf}&conta=${conta}';
    
02.06.2018 / 12:37