Open In App
Related Articles

JavaScript SyntaxError: Unterminated string literal

Improve Article
Improve
Save Article
Save
Like Article
Like

This JavaScript error unterminated string literal occurs if there is a string that is not terminated properly. String literals must be enclosed by single (‘) or double (“) quotes.

Message:

SyntaxError: Unterminated string constant (Edge)
SyntaxError: unterminated string literal (Firefox)

Error Type:

SyntaxError

What happened?

There is a string in the code which is not terminated. String literals need to be enclosed by single (‘) or double (“) quotes. JavaScript sees no difference between single-quoted strings and double-quoted strings.

Example 1: In this example, the single quotes are used and the string is not terminated, So the error has occurred.

Javascript




let GFG_str = 'This
is
                    GeeksForGeeks';
console.log(GFG_str);


Output(In console):

SyntaxError: Unterminated string constant

Example 2: In this example, the double quotes are used and the string is not terminated, So the error has occurred.

Javascript




let GFG_str = "This
is
                    GeeksForGeeks";
console.log(GFG_str);


Output(In console):

SyntaxError: Unterminated string constant
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 22 May, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials