How to write the following string ?

49 views Asked by At

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);
2

There are 2 answers

0
Avinash Raj On

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> '; 
0
Mark Verkiel On

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);