--- title: 'SyntaxError: "x" is a reserved identifier' slug: Web/JavaScript/Reference/Errors/Reserved_identifier tags: - Error - Errors - JavaScript - SyntaxError translation_of: Web/JavaScript/Reference/Errors/Reserved_identifier ---
SyntaxError: "x" is a reserved identifier (Firefox) SyntaxError: Unexpected reserved word (Chrome)
{{jsxref("SyntaxError")}}
予約語を識別子として使用した場合、エラーをスローします。これらは strict モードと通常モードの双方で予約されています:
enum
次のものは strict モードのコードでのみ予約されています:
implements
interface
package
private
protected
public
static
enum
識別子は全般的に予約されています。
var enum = { RED: 0, GREEN: 1, BLUE: 2 }; // SyntaxError: enum is a reserved identifier
strict モードのコードでは、より多くの識別子が予約されています。
"use strict"; var package = ["potatoes", "rice", "fries"]; // SyntaxError: package is a reserved identifier
これらの変数名を変更する必要があります。
var colorEnum = { RED: 0, GREEN: 1, BLUE: 2 }; var list = ["potatoes", "rice", "fries"];
たとえば、let
や class
をまだ実装していない古いブラウザーを使用している場合、それらの新しい言語機能をサポートしているより新しいブラウザーにアップデートすべきです。
"use strict"; class DocArchiver {} // SyntaxError: class is a reserved identifier // (たとえば、Firefox 44 以前の古いブラウザーはエラーをスローします)