JavaScript 予約キーワード


JavaScript では、一部の識別子は予約キーワードであり、変数名や関数名として使用できません。


JavaScript 標準

すべての最新ブラウザは ECMAScript 3(ES3、JavaScript の第3版、1999年から)を完全にサポートしています。

ECMAScript 4(ES4)は承認されませんでした。

ECMAScript 5(ES5、2009年リリース)。

ECMAScript 6(ES6、2015年リリース)は、JavaScript の最新の公式バージョンです。

時が経つにつれて、すべての最新ブラウザが ES6 を完全にサポートしていることがわかってきました。


JavaScript 予約キーワード

Javascript の予約キーワードは、変数、ラベル、関数名として使用できません。一部の予約キーワードは、Javascript の将来の拡張のために予約されています。

abstract arguments boolean break byte
case catch char class* const
continue debugger default delete do
double else enum* eval export*
extends* false final finally float
for function goto if implements
import* in instanceof int interface
let long native new null
package private protected public return
short static super* switch synchronized
this throw throws transient true
try typeof var void volatile
while with yield

* が付いたキーワードは、ECMAScript5 で新しく追加されたものです。


JavaScript オブジェクト、プロパティ、メソッド

JavaScript の組み込みオブジェクト、プロパティ、メソッドの名前を Javascript の変数名や関数名として使用することも避けるべきです:

Array Date eval function hasOwnProperty
Infinity isFinite isNaN isPrototypeOf length
Math NaN name Number Object
prototype String toString undefined valueOf


Java 予約キーワード

JavaScript は Java と一緒に使用されることがよくあります。一部の Java オブジェクトやプロパティを JavaScript の識別子として使用することは避けるべきです:

getClass java JavaArray javaClass JavaObject JavaPackage


Window 予約キーワード

JavaScript は HTML の外部でも使用できます。他の多くのアプリケーションでプログラミング言語として使用できます。

HTML では、移植性を考慮して、HTML および Window オブジェクトとプロパティの名前を Javascript の変数名や関数名として使用しないようにする必要があります:

alert all anchor anchors area
assign blur button checkbox clearInterval
clearTimeout clientInformation close closed confirm
constructor crypto decodeURI decodeURIComponent defaultStatus
document element elements embed embeds
encodeURI encodeURIComponent escape event fileUpload
focus form forms frame innerHeight
innerWidth layer layers link location
mimeTypes navigate navigator frames frameRate
hidden history image images offscreenBuffering
open opener option outerHeight outerWidth
packages pageXOffset pageYOffset parent parseFloat
parseInt password pkcs11 plugin prompt
propertyIsEnum radio reset screenX screenY
scroll secure select self setInterval
setTimeout status submit taint text
textarea top unescape untaint window


HTML イベントハンドラ

これに加えて、HTML イベントハンドラの名前を Javascript の変数名や関数名として使用することも避けるべきです。

例:

onblur onclick onerror onfocus
onkeydown onkeypress onkeyup onmouseover
onload onmouseup onmousedown onsubmit

その他の拡張