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 学习路径
跟踪您的进度 - 免费!