[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Lexical_grammar [Back]  [Original]

Lexical grammar - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Lexical grammar

Javascript lexical grammarECMAScript tokenECMAScript

In this article

U+200C <ZWNJ>
U+200D <ZWJ>
U+FEFF <BOM> Unicode

tokens

U+0009 <HT> \t
U+000B <VT> \v
U+000C <FF> \f
U+0020 <SP>
U+00A0 <NBSP>
Unicode <USP>

Javascript \s

ECMAScript Unicode Next Line, NEL, U+0085

U+000A <LF> UNIX \n
U+000D <CR> Commodore Mac \r
U+2028 <LS>
U+2029 <PS>

Javascript

Javascript

//;

js
function comment() {
  //  Javascript 
  console.log("Hello world!");
}
comment();

/* */

js
function comment() {
  /*  Javascript  */
  console.log("Hello world!");
}
comment();

js
function comment() {
  /* 
      */
  console.log("Hello world!");
}
comment();

js
function comment(x) {
  console.log("Hello " + x /*  x  */ + " !");
}
comment("world");

js
function comment() {
  /* console.log('Hello world!'); */
}
comment();

console.log()

ECMAScript 2015

ECMAScript

  • enum

  • implements
  • interface
  • let
  • package
  • private
  • protected
  • public
  • static

  • await

ECMAScript (ECMAScript 1 3)

  • abstract
  • boolean
  • byte
  • char
  • double
  • final
  • float
  • goto
  • int
  • long
  • native
  • short
  • synchronized
  • throws
  • transient
  • volatile

null, true false (literal) ECMAScript

( IdentifierNames) es5.github.com/#A.1 IdentifierNames

js
a.import
a['import']
a = { import: 'test' }.

IdentifierName FunctionDeclaration, FunctionExpression, VariableDeclaration ? IdentifierName MemberExpression, CallExpression

js
function import() {} // .

Null

null

js
null

Boolean

js
true
false

js
1234567890
42

// 
0888 // 888 
0777 // ,  511

(0) 8 Firefox bug 957513 parseInt()

B0b 0B ECMAScript 2015 0b 0 10b SyntaxError

js
0b10000000000000000000000000000000 // 2147483648
0b01111111100000000000000000000000 // 2139095040
0B00000000011111111111111111111111 // 8388607

O0o 0O ECMAScript 2015 0o 012345670o SyntaxError

js
0O755 // 493
0o644 // 420

"X" (0x 0X) 0x (0123456789ABCDEF) "" SyntaxError

js
0xFFFFFFFFFFFFFFFFF // 295147905179352830000
0x123456789ABCDEF   // 81985529216486900
0XA                 // 10

Object Object initializer

js
var o = { a: "foo", b: "bar", c: 42 };

//  (ES2015 )
var a = "foo",
  b = "bar",
  c = 42;
var o = { a, b, c };

// ES2015 
var o = { a: a, b: b, c: c };

Array

js
[1954, 1974, 1990, 2014]

js
'foo'
"bar"

js
"\xA9" // ""

Unicode

Unicode \u 4 UTF-16 2 0~FFFF Unicode (surrogate pair) ( wiki)

js
"\u00A9" // ""

Unicode

ECMAScript 2015 Unicode ( 0x10FFFF) FFFF

String.fromCodePoint() String.prototype.codePointAt()

js
"\u{2F804}"

// 
"\uD87E\uDC04"

RegExp

js
/ab+c/g

// 
// 
/(?:)/

template strings

js
`string text`

`string text line 1
 string text line 2`

`string text ${expression} string text`

tag `string text ${expression} string text`

JavaScript statements (ASI)

  • let, const,
  • import, export,
  • debugger
  • continue, break, throw
  • return

ECMAScript

1. "}"

js
{ 1 2 } 3

//  ASI 

{ 1 2 ;} 3;

2. token

++ b b ++

js
a = b
++c

//  ASI 

a = b;
++c;

3. restricted productions ""

  • (++ and --)
  • continue
  • break
  • return
  • yield, yield*
  • module
js
return
a + b

//  ASI 

return;
a + b;

Specification
ECMAScript 2027 LanguageSpecification


Web Proxy Viewer  |  New URL  |  Original Page