DEV Community


What JavaScript variable names are valid in ES5

・1 min read

ECMAScript 5.1:

An Identifier is an IdentifierName that is not a ReservedWord.

The reserved groups are: keywords, future reserved words, null literals and boolean literals.

Keywords in Javascript are tokens with special meaning: break, case, catch, continue, debugger, default, delete, do, else, finally, for, function, if, in, instanceof, new, return, switch, this, throw, try, typeof, var, void, while, with.

Future reserved words are the tokens that may become keywords in a future revision of ECMAScript: class, const, enum, export, extends, import, and super. Some future reserved words only apply in strict mode: implements, interface, let, package, private, protected, public, static, yield.

Null literal: null.

Boolean literals: true, false.

An identifier must contain any character from the following Unicode categories “Uppercase letter (Lu)”, “Lowercase letter (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number (Nl)”.

The article is a summary of the excellent article of Mathias Bynens:

Here is a validator for Javascript variables:

Discussion (0)