Variable name restrictions
A variable name cannot have spaces.
A variable name cannot have dashes (-
). Underscores (_
) are allowed and used instead.
A variable name cannot include any punctuation characters other than the dollar sign $
and underscore (_
).
A variable name cannot start with a number.
A variable name cannot be an existing keyword like const
or var
.
There are quite a few keywords cannot be used - return
, let
, class
, for
, if
, else
, etc. Most coding editors will change the color of the variable name to indicate that you are using a language keyword.
It is worth noting that despite type
being a keyword in TypeScript, you can still use type
as a variable name.
In general, you should use descriptive variable names that accurately describe the type of information they contain.