Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

SyntaxError: unterminated string literal

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!

Message

SyntaxError: unterminated string literal

Error type

SyntaxError

What went wrong?

There is an unterminated String somewhere. String literals must be enclosed by single (') or double (") quotes. JavaScript makes no distinction between single-quoted strings and double-quoted strings. Escape sequences work in strings created with either single or double quotes. To fix this error, check if:

  • you have opening and closing quotes (single or double) for your string literal,
  • you have escaped your string literal correctly,
  • your string literal works correctly over multiple lines, if any.

Examples

Multiple lines

You can't split a string across multiple lines like this in JavaScript:

var longString = "This is a very long string which needs 
                  to wrap across multiple lines because 
                  otherwise my code is unreadable.";
// SyntaxError: unterminated string literal

Instead, use the + operator, a backslash, or template literals. The + operator variant looks like this:

var longString = "This is a very long string which needs " +
                 "to wrap across multiple lines because " +
                 "otherwise my code is unreadable.";

Or you can use the backslash character ("\") at the end of each line to indicate that the string will continue on the next line. Make sure there is no space or any other character after the backslash (except for a line break), or as an indent; otherwise it will not work. That form looks like this:

var longString = "This is a very long string which needs \
to wrap across multiple lines because \
otherwise my code is unreadable.";

Another possibility is to use template literals, which are supported in ECMAScript 2015 environments:

var longString = `This is a very long string which needs 
                  to wrap across multiple lines because
                  otherwise my code is unreadable.`;

See also

문서 태그 및 공헌자

 이 페이지의 공헌자: fscholz
 최종 변경: fscholz,