Friday, September 5, 2025
HomeLanguagesJavascriptJavaScript SyntaxError: Unterminated string literal

JavaScript SyntaxError: Unterminated string literal

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
RELATED ARTICLES

Most Popular

Dominic
32265 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS