zoukankan      html  css  js  c++  java
  • javascript保留字趣史

    转载自[https://mathiasbynens.be/notes/reserved-keywords](https://mathiasbynens.be/notes/reserved-keywords)

    JavaScript中的保留关键字

    寻找JavaScript中所有保留字的列表? 你来对地方了。 我最近自己也需要这样一个列表,但最终还是比较了所有ECMAScript版本中的保留关键字。 结果列在下面,供将来参考。

    ECMAScript 1

    一开始,有 ECMAScript 1 它列出了以下保留字:

    do
    if
    in
    for
    new
    try
    var
    case
    else
    enum
    null
    this
    true
    void
    with
    break
    catch
    class
    const
    false
    super
    throw
    while
    delete
    export
    import
    return
    switch
    typeof
    default
    extends
    finally
    continue
    debugger
    function

    ECMAScript 2

    后来, ECMAScript2 加入了 int byte char goto long final float short double native public static throws boolean package private abstract volatile interface protected transient implements instanceof ,和 synchronized

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

    ECMAScript 3

    ECMAScript 3 没有在保留关键字列表中引入更改 - 它与ECMAScript 2关键字相同。

    ECMAScript 4

    没有 ECMAScript 4 这样的东西

    ECMAScript 5

    EcmaScript 5 / 5.1 移除了 int byte char goto long final float short double native throws boolean abstract volatile transient ,和 synchronized ; 它补充了 let ,和 yield作为保留字 

    do
    if
    in
    for
    let
    new
    try
    var
    case
    else
    enum
    eval
    null
    this
    true
    void
    with
    break
    catch
    class
    const
    false
    super
    throw
    while
    yield
    delete
    export
    import
    public
    return
    static
    switch
    typeof
    default
    extends
    finally
    package
    private
    continue
    debugger
    function
    arguments
    interface
    protected
    implements
    instanceof

    需要注意的是 implements let private public interface package protected static ,和 yield 仅在严格模式下是不允许的。

    您可能已经注意到我将 eval arguments 包括在列表中。 这些并不是严格的保留字,但他们确实 具有像关键字一样的行为 - 他们也被严格禁止。

    此外, 全局对象 的(未列出的) NaN Infinity undefined 属性在ES5中是不变的或只读属性。 所以即使 var NaN = 42; 这样的代码不会抛出错误,但是它也不会做任何事情。 为了避免混淆,我建议完全避免使用这些标识符,即使它们不是严格保留字。

    ECMAScript 6

    ECMAScript 6 await 作为module中的未来保留字  let yield 现在即使在非严格模式中页不允许作为变量名。 某些情况下 yield 起到标识符的作用。

    do
    if
    in
    for
    let
    new
    try
    var
    case
    else
    enum
    eval
    null
    this
    true
    void
    with
    await
    break
    catch
    class
    const
    false
    super
    throw
    while
    yield
    delete
    export
    import
    public
    return
    static
    switch
    typeof
    default
    extends
    finally
    package
    private
    continue
    debugger
    function
    arguments
    interface
    protected
    implements
    instanceof

    保留字有什么用途?

    保留的关键字不能用作 JavaScript中的变量名称 为了与旧版本的JavaScript引擎保持最佳的后向兼容性,最好避免将此页面上的关键字用作变量名称或 属性名称 - 即使是旧的ECMAScript 2中的保留字,类似于 char default

  • 相关阅读:
    2017/7/26 SCJP英语学习
    JSF(JavaServer Faces)简介
    Java回话技术
    2.2 对象深拷贝、浅复制、序列化
    编码与解码
    pycharm 教程(一)安装和首次使用
    Java Eclipse进行断点调试
    详细介绍如何在Eclipse中使用SVN
    SVN客户端安装与使用
    炸鸡
  • 原文地址:https://www.cnblogs.com/imgss/p/8886781.html
Copyright © 2011-2022 走看看