JavaScript 保留字
在 JavaScript 中,您不能將這些保留字用作變數、標籤或函式名。
abstract |
arguments |
await* |
boolean |
break |
byte |
case |
catch |
char |
class* |
const* |
continue |
debugger |
default |
刪除 |
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 |
公共 |
return |
short |
static |
super* |
switch |
synchronized |
this |
throw |
throws |
transient |
true |
try |
typeof |
var |
void |
volatile |
while |
with |
yield |
標記為*的單詞是
ECMAScript 5 和
ECMAScript 6 中的新內容。
您可以在 JS 版本章節中瞭解更多關於不同 JavaScript 版本的資訊。
已移除的保留字
以下保留字已從 ECMAScript 5/6 標準中移除。
abstract |
boolean |
byte |
char |
double |
final |
float |
goto |
int |
long |
native |
short |
synchronized |
throws |
transient |
volatile |
請不要將這些詞用作變數。ECMAScript 5/6 在所有瀏覽器中並不完全支援。
JavaScript 物件、屬性和方法
您還應該避免使用 JavaScript 內建物件、屬性和方法的名稱。
陣列 |
Date |
eval |
function |
hasOwnProperty |
Infinity |
isFinite |
isNaN |
isPrototypeOf |
length |
Math |
NaN |
name |
Number |
物件 |
prototype |
字串 |
toString |
undefined |
valueOf |
Java 保留字
JavaScript 經常與 Java 一起使用。您應該避免使用某些 Java 物件和屬性作為 JavaScript 識別符號。
getClass |
java |
JavaArray |
javaClass |
JavaObject |
JavaPackage |
|
|
其他保留字
JavaScript 可用作許多應用程式的程式語言。
您還應該避免使用 HTML 和 Window 物件和屬性的名稱。
alert |
all |
anchor |
anchors |
area |
assign |
blur |
button |
checkbox |
clearInterval |
clearTimeout |
clientInformation |
關閉 |
closed |
confirm |
constructor |
crypto |
decodeURI |
decodeURIComponent |
defaultStatus |
document |
元素 |
元素 |
embed |
embeds |
encodeURI |
encodeURIComponent |
escape |
事件 |
fileUpload |
focus |
form |
forms |
frame |
innerHeight |
innerWidth |
layer |
圖層 |
連結 |
location |
mimeTypes |
navigate |
navigator |
frames |
frameRate |
hidden |
歷史 |
圖片 |
images |
offscreenBuffering |
open |
opener |
option |
outerHeight |
outerWidth |
packages |
pageXOffset |
pageYOffset |
parent |
parseFloat |
parseInt |
password |
pkcs11 |
plugin |
prompt |
propertyIsEnum |
收音機 |
reset |
screenX |
screenY |
scroll |
secure |
select |
self |
setInterval |
setTimeout |
status |
submit |
taint |
text |
textarea |
top |
unescape |
untaint |
window |
|
|
|
HTML 事件處理程式
此外,您還應避免使用所有 HTML 事件處理程式的名稱。
示例
onblur |
onclick |
onerror |
onfocus |
onkeydown |
onkeypress |
onkeyup |
onmouseover |
onload |
onmouseup |
onmousedown |
onsubmit |
W3schools 學習路徑
跟蹤您的進度 - 免費!