Programming Search⌘K

Featureadvanced

Punctuators

Also called operators and delimiters, Punctuator, OptionalChainingPunctuator, DivPunctuator, RightBracePunctuator, operator tokens.

The punctuators are the operator and delimiter tokens. The scanner takes the longest one, and the goal symbol decides if / divides or starts a regex, and if } ends a block or a template part.

Language
JavaScript

Synopsis

OtherPunctuator  { ( ) [ ] . ... ; , < > <= >= == != === !== + - * % ** ++ --
                 << >> >>> & | ^ ! ~ && || ?? ? : = += -= *= %= **= <<= >>=
                 >>>= &= |= ^= &&= ||= ??= =>
OptionalChainingPunctuator  ?.   (not before a decimal digit)
DivPunctuator               / /=
RightBracePunctuator        }

Punctuators are the tokens that are neither names nor literals: the operators, the brackets and the separators.1 MDN calls them "punctuators (mostly operators)".2 The meaning of each operator is in the pages of the operators; this page is about the tokens.

Semantics

r1. The token list. The grammar of 12.8 lists the punctuators in four productions: OptionalChainingPunctuator, OtherPunctuator, DivPunctuator and RightBracePunctuator.1 Punctuator, the first two, is part of CommonToken. "The DivPunctuator, RegularExpressionLiteral, RightBracePunctuator, and TemplateSubstitutionTail productions derive additional tokens that are not included in the CommonToken production."1

r2. The longest match. The scanner takes "the longest possible sequence of code points as the next input element".1 So >>>= is one token, not >> and >=, and n --> 0 is n -- > 0. The rule looks only at the characters: x+++++x is x ++ ++ + x, which does not parse, while x++ + ++x with spaces does. Examples: tokens, five-plus.

r3. ?. before a digit. The token ?. is OptionalChainingPunctuator only when "[lookahead ∉ DecimalDigit]".1 The rule keeps the old meaning of a conditional with a decimal fraction: yes?.5:1 is yes ? .5 : 1. Example: tokens.

r4. / and /=. These are not in Punctuator, because the same character can start a RegularExpressionLiteral. The goal symbol InputElementDiv has DivPunctuator, and InputElementRegExp has RegularExpressionLiteral.1 Where an operand can come, as at the start of a statement or after ( or =, the / starts a regular expression. After an operand it is division (Lexical grammar). Example: slash.

r5. // and the empty regex. "Regular expression literals may not be empty; instead of representing an empty regular expression literal, the code unit sequence // starts a single-line comment. To specify an empty regular expression, use: /(?:)/."1 Example: slash.

r6. } in templates. A } ends a block, an object literal or a template substitution. In a template, the TemplateMiddle and TemplateTail tokens start with }, so the scanner must know that a substitution is open.1 The goal symbol InputElementTemplateTail, or InputElementRegExpOrTemplateTail, gives that context, and InputElementDiv and InputElementRegExp have RightBracePunctuator instead.1 Example: slash.

Examples

The examples run with Node.js 24.

The rules of the longest match and of ?. (rules r2 and r3):

const yes = true;
const missing = null;
console.log(yes?.5:1);
console.log(missing?.length, missing ?? "default");

let n = 3;
const seen = [];
while (n --> 0) seen.push(n);
console.log(seen);

let x = 8;
x >>>= 1;
const add = (a, b) => a + b;
console.log(x, add(x, 1) >= 5);
Output
0.5
undefined default
[ 2, 1, 0 ]
4 true

The loop condition n --> 0 is n-- > 0; there is no --> operator.

The / and } cases of rules r4 to r6. In the first line, {} is a block at the start of a statement, so the / after it starts a regular expression. In the second line, ({}) is an operand, so the / divides. In the third line both slashes follow operands. The last line has two substitutions, each with a } of its own inside:

console.log(eval("{} /foo/.source"));
console.log(eval("({}) / 2"));
console.log(eval("let a = 6, g = 2; a /2/ g"));
console.log(String(new RegExp("")), /(?:)/.test("any text"));
console.log(`a${ { x: 1 }.x }b${ [2, 3].length }c`);
Output
foo
NaN
1.5
/(?:)/ true
a1b2c

The longest match does not look at the grammar (rule r2). Without spaces, the scanner reads ++ twice after x:

This code raises SyntaxError, on purpose.

let x = 1;
const y = x+++++x;
console.log(y);

Node.js reports SyntaxError: Unexpected token '++'. With spaces, x++ + ++x is valid.

Pitfalls

Joined operators

a+++b, a-->b and x+++++x depend on the longest match (rule r2). Put spaces around binary operators so that the reader sees the same tokens as the scanner.

?. with a number after it

obj?.5 is not optional property access, because of the lookahead of rule r3. To read a property with a numeric name, use obj?.[5].1

A line that starts with / or a template

After an operand, a / at the start of a line is division (rule r4), and a template literal at the start of a line continues the expression before it as a tagged template. Both are cases for an explicit semicolon (Automatic semicolon insertion).1

Comparison

Token JavaScript Python
// starts a comment1 an operator3
===, !== strict equality not in the list3
?., ?? optional chaining, nullish coalescing1 not in the list3
++, -- increment, decrement1 not in the list3
:=, @ not in the list1 operators3
tie-break the longest token1 the longest token3

Python lists its tokens as operators and delimiters (Operators and delimiters). The same two characters // are a comment in JavaScript and an operator in Python. Both lexers use the longest match.

References

  1. ECMAScript 2026 Language Specification, 12 ECMAScript Language: Lexical Grammar; 12.6 Tokens; 12.8 Punctuators; 12.9.5 Regular Expression Literals; 12.9.6 Template Literal Lexical Components
  2. Lexical grammar, MDN, introduction
  3. Lexical analysis, The Python Language Reference, 2.1.9 Whitespace between tokens; 2.7 Operators and delimiters

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • a history with a source