How to use the JS variable name validator
- Type or paste into Names (one per line). Blank lines are ignored.
- Read the summary, for example Valid: 7 of 12.
- Check the table: Name, Verdict, Notes with each problem or warning, and Suggestion for invalid names.
What it does and when to use it
Use it when you generate code from data, such as turning column headers or API field names into variables, and need to know which ones will break. It also answers quick questions while you code, like whether $el or _private is allowed, or why my-var throws a syntax error.
When a whole snippet will not parse, check it with the JavaScript validator. To convert many labels to camelCase or snake_case, use the developer case converter. The JS Unicode escaper shows the escape form of non-ASCII names.
How it works
Each name is tested against the identifier rules in the ECMAScript specification:
- First character. A Unicode letter (ID_Start),
$or_. A digit or a symbol fails. - Other characters. Letters, digits, combining marks (ID_Continue),
$,_and the zero-width joiner characters. Spaces, hyphens, dots and other symbols fail, and each bad character is listed. - Reserved words. The 36 keywords and literals such as
class,const,enum,nullandtrueare always invalid. Nine more, includinglet,staticandyield, are invalid in strict mode. - Warnings.
awaitcannot be a name in modules or async functions,evalandargumentscannot be assigned in strict mode, built-ins such asundefinedare shadowed, and ALL_CAPS is noted as a constant style.
Worked examples
The default list gives Valid: 7 of 12. Some rows from the table:
| Name | Verdict | Notes | Suggestion |
|---|---|---|---|
| userName | Valid | — | |
| 2fa | Invalid | Starts with a digit | _2fa |
| first name | Invalid | Contains whitespace | firstName |
| class | Invalid | “class” is a reserved word | _class |
| let | Invalid | Reserved in strict mode | _let |
| my-var | Invalid | Character “-” not allowed | myVar |
| café | Valid | — | |
| undefined | Valid | Shadows a built-in meaning | |
| await | Valid | Not usable in modules or async functions |
The Notes column here is shortened; the tool gives a full sentence for each.
Limits and tips
- Context is not checked. A valid name can still clash with a variable already declared in the same scope.
- Escape sequences in names, such as
abc, are not decoded; type the real characters. - Valid is not the same as good. Pick names that describe the value; the tool checks only the syntax rules.
Frequently asked questions
Can a JavaScript variable name contain accented letters or other scripts?
Why is let marked invalid when old code uses it as a name?
Is undefined a valid variable name?
Can property names use reserved words?
How is the suggestion built?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.