Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

SyntaxError: string literal contains an unescaped line break

The JavaScript error "string literal contains an unescaped line break" occurs when there is an unterminatedstring literal somewhere. String literals must be enclosed by single(') or double (") quotes and cannot split across multiple lines.

Message

SyntaxError: Invalid or unexpected token (V8-based)SyntaxError: '' string literal contains an unescaped line break (Firefox)SyntaxError: Unexpected EOF (Safari)

Error type

What went wrong?

There is an unterminatedstring literal somewhere. String literals must beenclosed by single (') or double (") quotes. JavaScript makesno distinction between single-quoted strings and double-quoted strings.Escape sequences workin 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 isn't split across multiple lines.

Examples

Multiple lines

You can't split a string across multiple lines like this in #"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, ortemplate literals.The+ operator variant looks like this:

js
const 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 thatthe string will continue on the next line. Make sure there is no space or any othercharacter after the backslash (except for a line break), or as an indent; otherwise itwill not work. That form looks like this:

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

Another possibility is to usetemplate literals.

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

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.

View this page on GitHubReport a problem with this content

[8]ページ先頭

©2009-2025 Movatter.jp