保留字
JavaScript 的保留字包括關鍵字 (keyword) 、未來保留字 (future reserved word) 、三個字面常數,分別是 null 、 true 、 false 。
關鍵字為具有語法功能的標記,如下表
| break | delete | function | return | typeof |
| case | do | if | switch | var |
| catch | else | in | this | void |
| continue | finally | instanceof | throw | while |
| default | for | new | try | with |
未來保留字為將來有打算列入關鍵字之中的,如下表
| abstract | double | implements | private | throws |
| boolean | enum | import | protected | transient |
| byte | export | int | public | volatile |
| char | extends | interface | short | |
| class | final | long | static | |
| const | float | native | super | |
| debugger | goto | package | synchronized |
識別字
識別字為寫程式時依需求自行定義的名稱,包括變數 (variable) 、函數 (function) 等,皆為使用自行定義的識別字。除了保留字、 null 、 true 、 false 之外, JavaScript 習慣上使用英文字母大寫 A-Z (\u0041-\u005a),小寫 a-z (\u0061-\u007a) ,底線符號 (_, \u005f) , dollar sign ($, \u0024) 與數字 0-9 (\u0030-\u0039) 為主。
字面常數
字面常數的意思就是字面上的意義,也就是說, 1234 就代表整數數值一千兩百三十四的意義,因此,所謂的字面常數就是直接寫進 JavaScript 程式原始碼的數值,依資料型態分類有
- 數字字面常數 (integer literal)
- 字串字面常數 (string literal)
- 布林字面常數 (Boolean literal)
- Null 字面常數 (null literal)
數字字面常數就是一般的數字,如整數 1234 ,或帶小數點的浮點數 123.4 等。字串字面常數就是用單引號或雙引號圍起來的文字資料,如 "Hello, JabaScript!" 等。布林字面常數就是 true 與 false ,而 Null 字面常數就是 null 。
運算子
JavaScript 提供多樣、功能完整的運算子,如下列表
| { } ( ) [ ] |
| . ; , < > <= |
| >= == != === !== |
| + - * % ++ -- |
| << >> >>> & | ^ |
| ! ~ && || ?: |
| = += -= *= %= <<= |
| >>= >>>= &= |= ^= |
| / /= |
| 中英文術語對照 | |
|---|---|
| 瀏覽器 | browser |
| 保留字 | reserved word |
| 識別字 | identifier |
| 字面常數 | literal |
| 運算子 | operator |
| 關鍵字 | keyword |
| 未來保留字 | future reserved word |
| 變數 | variable |
| 函數 | function |
參考資料
http://www.ecma-international.org/publications/standards/Ecma-262.htm
http://www.w3schools.com/JS/js_variables.asp
http://www.ecma-international.org/publications/standards/Ecma-262.htm
http://www.w3schools.com/JS/js_variables.asp
沒有留言:
張貼留言