为什么它们不是关键字?它们是什么?
true, false, null
更新快答
这些是保留字,但不是关键字。
规范验证的小技术差异 - ES3 和 ES5
最佳答案
它们是 bool 文字。来自specification :
BooleanLiteral :: true false
- The value of the Boolean literal
true
is a value of the Boolean type, namelytrue
.- The value of the Boolean literal
false
is a value of the Boolean type, namelyfalse
.
这类似于 10
是一个数字文字 或 'foo'
是一个字符串文字。
保留字 包括关键字和文字。 true
和 false
是保留字,但不是关键字。以下是关键字:
break do instanceof typeof
case else new var
catch finally return void
continue for switch while
debugger function this with
default if throw
delete in try
请注意 true
和 false
没有出现在这个列表中。
我认为您的困惑来自于没有意识到关键字 和保留字 这两个术语是不同的。每个关键字都是保留字,但并非每个保留字都是关键字。
关于javascript - 'true' 和 'false' 和 'null' 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12288945/