this is my code
var text = "";
var text += "function "+ funcName + "(){";
var text += "\n";
and this is the error:
**Uncaught SyntaxError: Unexpected token += **
How can I solve it?
this is my code
and this is the error: **Uncaught SyntaxError: Unexpected token += ** How can I solve it? |
|||
You are redeclaring an already declared variable. Instead, you should have:
You can't |
|||||
|
You just need to declare your variables once.
|
|||
|
The
Or:
|
|||
|
Remove the var from the second line and third line, you are declaring a new variable from every line.
|
|||
|
var
on the lines after the first; it's completely unnecessary and it's causing your problem. – Pointy 13 hours agovar
it's like you're re-declaring the variable. – MelanciaUK 13 hours agovar
in a particular lexical context, you don't need to do it again. – Pointy 13 hours ago+=
is valid in avar
initializer clause? – Pointy 13 hours agovar
declarations are parsed and their identifiers are added as properties of the Environment Record object in the entering phase of the execution context. That means avar
re-declaration is redundant and does not re-initialize a variable. Try:var a=1; var a; alert(a);
alerts1
. However,+=
is not valid a token after the identifier of a variable declaration, hence the syntax error. – Fabrício Matté 13 hours ago