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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM