javascriptecmascript-2020

What‘s the difference between "identifier" and "identifierName" in ECMAScript 2020?


https://262.ecma-international.org/11.0/#prod-IdentifierName I don't undestand well the difference between "identifier" and "identifierName" in ECMAScript 2020.


Solution

  • In the ECMAScript specification, the lexical grammar doesn't 'know' anything about reserved words; any word-like thing is recognized as an IdentifierName. It's then up to the syntactic level to decide how to deal with an IdentifierName. If an IdentifierName doesn't match the ReservedWord production, then it qualifies as an Identifier, and (to a first approximation) can be used in all the places you'd expect an identifier. (The complete rules are somewhat complicated: see 12.6.2 Keywords and Reserved Words for a summary.)