Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common sources of unterminated string literal [duplicate]

I am trying to debug a JavaScript script that gets read in a Firefox extension and executed. I only can see errors via the Firebug console (my code is invisible to Firebug), and it's reporting a "unterminated string literal."

I checked the line and the lines around it and everything seems fine-parentheses, braces, and quotes are balanced, etc. What are other possible causes that I should be looking for?

like image 273
sutee Avatar asked Oct 22 '08 21:10

sutee


People also ask

What is unterminated string literal?

The JavaScript error "unterminated string literal" occurs when there is an unterminated string literal somewhere. String literals must be enclosed by single ( ' ) or double ( " ) quotes.

How do you fix unterminated string constant?

To solve the "Unterminated string constant" error, make sure to enclose your strings in quotes consistently. String literals must be enclosed in single quotes, double quotes or backticks. When writing a multiline string use backticks.


1 Answers

Most browsers seem to have problems with code like this:

var foo = "</script>"; 

In Firefox, Opera and IE8 this results in an unterminated string literal error. Can be pretty nasty when serializing html code which includes scripts.

like image 67
VoY Avatar answered Oct 04 '22 19:10

VoY