JavaScript/予約語
表示
この章では、変数や関数などの名前として使用できない、JavaScriptの予約語の一覧を掲載しています。
予約語の種類
[編集]ECMAScript の規格では、予約語(Reserved Words)を以下の四種類に分類しています(ES1当時)。
- Keyword
- キーワード
- FutureReservedWord
- 将来のために予約された単語
- NullLiteral
- ヌルリテラル
- null
- BooleanLiteral
- 論理型リテラル
- false と true
JavaScriptの予約語 予約語 説明 短い用例 async 非同期関数の定義 async function fetchData() { /* ... */ }
await 非同期関数内での非同期処理の待機 let result = await fetchData();
break ループやswitch文を終了 break;
case switch文内での選択肢 case 1: /* ... */
catch 例外処理のキャッチ try { /* ... */ } catch (e) { /* ... */ }
class クラスの定義 class MyClass { /* ... */ }
const 定数の宣言 const PI = 3.14;
continue ループの次の反復に進む continue;
debugger デバッガを起動 debugger;
default switch文のデフォルトの選択肢 default: /* ... */
delete オブジェクトのプロパティを削除 delete obj.property;
do do-whileループの開始 do { /* ... */ } while (condition);
else if文のelse部分 if (x > 0) { /* ... */ } else { /* ... */ }
export モジュールからのエクスポート export const myVar = 10;
extends クラスの継承 class SubClass extends SuperClass {}
false 真偽値の「偽」 let isActive = false;
finally try-catch文の最終実行部分 try { /* ... */ } finally { /* ... */ }
for forループの開始 for (let i = 0; i < 10; i++) { /* ... */ }
function 関数の定義 function myFunction() { /* ... */ }
if 条件分岐の開始 if (x > 0) { /* ... */ }
import モジュールのインポート import { myFunction } from './module';
in オブジェクトのプロパティが存在するか確認 'name' in obj; instanceof インスタンスの型を確認 obj instanceof MyClass;
let 変数の宣言(再代入可能) let counter = 0;
new 新しいオブジェクトの生成 let obj = new MyClass();
null 空の値(オブジェクトがないこと) let value = null;
return 関数からの戻り値 return result;
super 親クラスのメソッドやプロパティへのアクセス super.constructor();
switch 条件分岐のためのswitch文 switch (x) { case 1: /* ... */ break; }
this 現在のオブジェクトへの参照 console.log(this);
throw 例外を投げる throw new Error("Something went wrong");
true 真偽値の「真」 let isActive = true;
try 例外処理の開始 try { /* ... */ } catch (e) { /* ... */ }
typeof 変数の型を調べる typeof 42; // "number"
var 変数の宣言(旧式) var name = "Alice";
void 式の評価を行うが結果を返さない function foo() { return; }
while whileループの開始 while (condition) { /* ... */ }
with オブジェクトのプロパティに対してスコープを拡張(非推奨) with (Math) { let result = cos(0); }
yield ジェネレータ関数の値を返す function* generator() { yield 1; }
予約語の変遷
[編集]単語 | ES1 | ES2 | ES3 | ES5 | ES6/2015 | ES7/2016 | ES8/2017 |
---|---|---|---|---|---|---|---|
abstract | N/A | FRW | ← | N/A | ← | ← | ← |
await | N/A | ← | ← | ← | FRW | ← | K/W |
boolean | N/A | FRW | ← | N/A | ← | ← | ← |
break | K/W | ← | ← | ← | ← | ← | ← |
byte | N/A | FRW | ← | N/A | ← | ← | ← |
case | FRW | ← | K/W | ← | ← | ← | ← |
catch | FRW | ← | K/W | ← | ← | ← | ← |
char | N/A | FRW | ← | N/A | ← | ← | ← |
class | FRW | ← | ← | ← | K/W | ← | ← |
const | FRW | ← | ← | ← | K/W | ← | ← |
continue | K/W | ← | ← | ← | ← | ← | ← |
debugger | FRW | ← | ← | K/W | ← | ← | ← |
default | FRW | ← | K/W | ← | ← | ← | ← |
delete | K/W | ← | ← | ← | ← | ← | ← |
do | FRW | ← | K/W | ← | ← | ← | ← |
double | N/A | FRW | ← | N/A | ← | ← | ← |
else | K/W | ← | ← | ← | ← | ← | ← |
enum | FRW | ← | ← | ← | ← | ← | ← |
export | FRW | ← | ← | ← | K/W | ← | ← |
extends | FRW | ← | ← | ← | K/W | ← | ← |
false | Bool | ← | ← | ← | ← | ← | ← |
final | N/A | FRW | ← | N/A | ← | ← | ← |
finally | FRW | ← | K/W | ← | ← | ← | ← |
for | K/W | ← | ← | ← | ← | ← | ← |
float | N/A | FRW | ← | N/A | ← | ← | ← |
function | K/W | ← | ← | ← | ← | ← | ← |
goto | N/A | FRW | ← | N/A | ← | ← | ← |
if | K/W | ← | ← | ← | ← | ← | ← |
implements | N/A | FRW | ← | S/M | ← | ← | ← |
import | FRW | ← | ← | ← | K/W | ← | ← |
in | K/W | ← | ← | ← | ← | ← | ← |
instanceof | N/A | FRW | K/W | ← | ← | ← | ← |
int | N/A | FRW | ← | N/A | ← | ← | ← |
interface | N/A | FRW | ← | S/M | ← | ← | ← |
let | N/A | ← | ← | S/M | ← | ← | ← |
long | N/A | FRW | ← | N/A | ← | ← | ← |
native | N/A | FRW | ← | N/A | ← | ← | ← |
new | K/W | ← | ← | ← | ← | ← | ← |
null | Null | ← | ← | ← | ← | ← | ← |
package | N/A | FRW | ← | S/M | ← | ← | ← |
private | N/A | FRW | ← | S/M | ← | ← | ← |
protected | N/A | FRW | ← | S/M | ← | ← | ← |
public | N/A | FRW | ← | S/M | ← | ← | ← |
return | K/W | ← | ← | ← | ← | ← | ← |
short | N/A | FRW | ← | N/A | ← | ← | ← |
static | N/A | FRW | ← | S/M | ← | ← | ← |
super | FRW | ← | ← | ← | K/W | ← | ← |
switch | FRW | ← | K/W | ← | ← | ← | ← |
synchronized | N/A | FRW | ← | N/A | ← | ← | ← |
this | K/W | ← | ← | ← | ← | ← | ← |
throw | FRW | ← | K/W | ← | ← | ← | ← |
throws | N/A | FRW | ← | N/A | ← | ← | ← |
transient | N/A | FRW | ← | N/A | ← | ← | ← |
true | Bool | ← | ← | ← | ← | ← | ← |
try | FRW | ← | K/W | ← | ← | ← | ← |
typeof | K/W | ← | ← | ← | ← | ← | ← |
var | K/W | ← | ← | ← | ← | ← | ← |
void | K/W | ← | ← | ← | ← | ← | ← |
volatile | N/A | FRW | ← | N/A | ← | ← | ← |
while | K/W | ← | ← | ← | ← | ← | ← |
with | K/W | ← | ← | ← | ← | ← | ← |
yield | N/A | ← | ← | S/M | K/W | ← | ← |
- N/A
- 予約語ではない
- FRW
- Future Reserved Word : 将来のために予約された単語
- K/W
- Keyword : キーワード
- S/M
- Strict mode : Strict モードでのみ将来のために予約された単語として識別子には使用できない。
- ←
- 左に同じ
カテゴリ別一覧
[編集]JavaScript (ECMAScript) の予約語は、変数名や関数名、識別子として使用できない特定のキーワードや将来の予約語です。以下は最新の ECMAScript の仕様に基づく予約語の一覧です。
キーワード (Keywords)
[編集]JavaScript の文法構造を定義するために使用される予約語。
await break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof let new null return super switch this throw true try typeof var void while with yield
将来の予約語 (Future Reserved Words)
[編集]現在は未使用ですが、将来の仕様で使用される可能性がある予約語。
Strict モードで予約
[編集]以下の予約語は strict モードでは使用できません。
implements interface package private protected public static
ECMAScript 5 で定義された予約語
[編集]let yield
リテラル (Literals)
[編集]特定の値を表す予約語で、識別子として使用できません。
null true false
グローバルオブジェクト
[編集]グローバルスコープで予約されているオブジェクト名。
Array ArrayBuffer BigInt BigInt64Array BigUint64Array Boolean DataView Date decodeURI decodeURIComponent encodeURI encodeURIComponent Error eval EvalError Float32Array Float64Array Function globalThis Infinity Int16Array Int32Array Int8Array Intl isFinite isNaN JSON Map Math NaN Number Object parseFloat parseInt Promise Proxy RangeError ReferenceError Reflect RegExp Set String Symbol SyntaxError TypeError Uint16Array Uint32Array Uint8Array Uint8ClampedArray undefined URIError WeakMap WeakSet
モジュール専用予約語
[編集]モジュールの中で特定の文法に使われる予約語。
import export await
補足
[編集]- これらの予約語は識別子として使えないため、変数名や関数名にすることは避けてください。
- 将来の予約語については、使用すると互換性の問題が生じる可能性があります。