-1

I want to write the following string, but it gives the error - Uncaught SyntaxError: Unexpected identifier

var str=" <span class="math-tex"> /( /sum /) </span> "; 
console.log(str);
  • 1
    Please start with a basic tutorial such as http://www.codecademy.com/en/tracks/javascript - your error isin your use of " – Toby Allen Jun 21 '15 at 13:41

2 Answers2

2

In this case you need to escape the quotes within the declaration of the string.

var str=" <span class=\"math-tex\"> /( /sum /) </span> "; 
console.log(str);

Or use single quotes.

var str=" <span class='math-tex'> /( /sum /) </span> "; 
console.log(str);
Mark Verkiel
  • 1,229
  • 10
  • 21
1

Use single quotes. It fails because your input string contains double quotes and the quotes you actually used to assign that string to a variable is also double quotes. So when the interpreter sees the second double quotes, it would consider that point as end of the string.

var str= ' <span class="math-tex"> /( /sum /) </span> '; 
Avinash Raj
  • 166,785
  • 24
  • 204
  • 249