Did you know
The ECMAScript 5.1 spec says:
Identifier is an
IdentifierName that is not a
The spec describes four groups of reserved words: keywords, future reserved words, null literals and boolean literals.
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, and with.
Future reserved words are tokens that may become keywords in a future revision of ECMAScript:
super. Some future reserved words only apply in strict mode:
The null literal is, simply,
There are two boolean literals:
false. None of the above are allowed as variable names.
Non-reserved words that act like reserved words
undefined properties of the global object are immutable or read-only properties in ES5.1. So even though
var NaN = 42; in the global scope wouldn’t throw an error, it wouldn’t actually do anything. To avoid confusion, I’d suggest avoiding the use of these variable names.
In strict mode,
arguments are disallowed as variable names too. (They kind of act like keywords in that case.) The old ES3 spec defines some reserved words that aren’t reserved words in ES5 anymore:
int, byte, char, goto, long, final, float, short, double, native, throws, boolean, abstract, volatile, transient, and synchronized.
It’s probably a good idea to avoid these as well, for optimal backwards compatibility.
Valid identifier names
As mentioned before, the spec differentiates between identifier names and identifiers. Identifiers form a subset of identifier names, since identifiers have the extra restriction that no reserved words are allowed. For example,
var is a valid identifier name, but it’s an invalid identifier.
So, what is allowed in an identifier name?
An identifier must start with
_, or any character in the Unicode categories “Uppercase letter (Lu)”, “Lowercase letter (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number (Nl)”.
Unicode escape sequences are also permitted in an
IdentifierName, where they contribute a single character. […] A
UnicodeEscapeSequence cannot be used to put a character into an
IdentifierName that would otherwise be illegal.
This means that you can use
var \u0061 and
var a interchangeably. Similarly, since
var 1 is invalid, so is
IdentifierNames that are canonically equivalent according to the Unicode standard are not equal unless they are represented by the exact same sequence of code units.
man\u0303ana are two different variable names, even though they’re equivalent after Unicode normalization.
Examples inside vRO
Can you use them in between scripts?
Interestingly, we can also use this variable names not only in the scripts but also, out of them i.e. as inputs, outputs and attributes. See this action’s input:
As we see, vRO raises an alarm here saying that
Parameter name can contain only letters, numbers, and the symbols "_" and "$". Parameter name cannot start or end with ".".
However, when I run this action, it runs perfectly normal.
I think it is quite amusing. If used dexterously, it could give another dimension to your code. 👽