From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../errors/unterminated_string_literal/index.html | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 files/ja/web/javascript/reference/errors/unterminated_string_literal/index.html (limited to 'files/ja/web/javascript/reference/errors/unterminated_string_literal') diff --git a/files/ja/web/javascript/reference/errors/unterminated_string_literal/index.html b/files/ja/web/javascript/reference/errors/unterminated_string_literal/index.html new file mode 100644 index 0000000000..be1022bda4 --- /dev/null +++ b/files/ja/web/javascript/reference/errors/unterminated_string_literal/index.html @@ -0,0 +1,67 @@ +--- +title: 'SyntaxError: unterminated string literal' +slug: Web/JavaScript/Reference/Errors/Unterminated_string_literal +tags: + - Errors + - JavaScript + - SyntaxError +translation_of: Web/JavaScript/Reference/Errors/Unterminated_string_literal +--- +
{{jsSidebar("Errors")}}
+ +

メッセージ

+ +
SyntaxError: unterminated string literal
+
+ +

エラータイプ

+ +

{{jsxref("SyntaxError")}}

+ +

何がうまくいかなかったのか?

+ +

どこかに終端されていない {{jsxref("String")}} があります。文字列リテラルは、シングル(')かダブル(")のクオートで囲む必要があります。JavaScript は、シングルクオート文字列とダブルクオート文字列を区別しません。エスケープシーケンス はシングルクオートとダブルクオート、どちらの文字列でも動作します。このエラーを修正するためには、次の点をチェックしてください:

+ + + +

+ +

複数行

+ +

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
+ +

替わりに、+ 演算子 かバックスラッシュ、template literal を使用します。+ 演算子だと、次のようになります:

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

または、文字列が次のように続くことを示すために、各行の終わりにバックスラッシュ文字("\")を使用することもできます。バックスラッシュの後に、(改行を除いて)スペースや文字、インデントを入れないようにしてください。そうしないと動作しません。バックスラッシュの場合、次のようになります:

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

ECMAScript 2015 環境でサポートされている template literal を使っても改行可能です。

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

関連情報

+ + -- cgit v1.2.3-54-g00ecf