javascript - 'true' 和 'false' 和 'null' 是什么?

标签 javascript keyword

为什么它们不是关键字?它们是什么?

true, false, null

更新快答

这些是保留字,但不是关键字。

规范验证的小技术差异 - ES3 和 ES5

最佳答案

它们是 bool 文字。来自specification :

BooleanLiteral ::
   true
   false
  • The value of the Boolean literal true is a value of the Boolean type, namely true.
  • The value of the Boolean literal false is a value of the Boolean type, namely false.

这类似于 10 是一个数字文字'foo' 是一个字符串文字

保留字 包括关键字和文字。 truefalse保留字,但不是关键字。以下是关键字:

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

请注意 truefalse 没有出现在这个列表中。

我认为您的困惑来自于没有意识到关键字保留字 这两个术语是不同的。每个关键字都是保留字,但并非每个保留字都是关键字。

关于javascript - 'true' 和 'false' 和 'null' 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12288945/

相关文章:

javascript - 按类别限制 Div 数量

javascript - javascript中的函数相等

javascript - NodeJS 中的递归异步循环

javascript - 饼图 d3.js

javascript - 在输入更改状态时使用 jquery 更改表单 url 查询参数

java - java中private、static、final、public、abstract关键字的使用模式

python - 如何在 Python 中编写一个永远在线的 "Quit"选项?

sql - 如何选择30天的数据?

seo - 元关键字标签中哪些被认为是重复的 "words"?

c# - C# 'event' 关键字的多重含义?