js 基础篇--保留字

1、js把一些标识符拿出来用作自己的关键字。因此,就不能再在程序中把这些关键字用作标识符了:

1 break         delete         function          return        typeof   
2 case           do             if               switch         var   
3 catch          else           in               this           void    
4 continue       false          instanceof       throw          while   
5 debugger       finally        new              true           with   
6 default         for           null             try

2、js同样保留了一些关键字,这些关键字在当前语言版本中并没有用到,但在未来版本中可能会用到。ES5保留了这些关键字:  

class    const    enum    export    extends    import    super

3、此外,下面的这些关键字在普通的 js 代码中是合法的,但是在严格模式下是保留字:  

1 implements    let      private      public    yield 
2 interface     package   protected      static

4、严格模式同样对下面的标识符的使用做了严格限制,它们并不完全是保留字,但不能用作变量名、函数名或参数名

 1 arguments   eval 

5、ES3 将 Java 的所有关键字都列为自己的保留字,尽管这些保留字在 ES5 中放宽了限制,但如果你希望代码能在基于 ES3 实现的解释器上运行的话,应当避免使用这些关键字作为标识符:

1 abstract      double      goto        native      static    
2 boolean       enum       implements     package      super
3 byte         export      inport       private      synchronized    
4 char         extends     int         protected     throws    
5 class        final      interface     public       transient    
6 const        float      long        short       volatile

6、js 预定义了很多全局变量和函数,应当避免把它们的名字当做变量名和函数名

1 arguments        encodeURI        Infinity        Number        RegExp    
2 Array          encodeURIComponent   isFinite        Object        String    
3 Boolean          Error          isNaN          parseFloat     SyntaxError
4 Date            eval          JSON           parseInt      TypeError
5 decodeURI          EvalError        Math          RangeError     undefined
6 decodeURIComponent    Function        NaN           ReferenceError   URIError

猜你喜欢

转载自www.cnblogs.com/kristen-zou/p/10868565.html