DEV Community

loading...

What JavaScript variable names are valid in ES5

dmanias
・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:
https://mathiasbynens.be/notes/javascript-identifiers

Here is a validator for Javascript variables: https://mothereff.in/js-variables#%E0%B2%A0%5f%E0%B2%A0

Discussion (0)