JS Reserved Words
Reserved words can't be used as variable, parameter, or property names. Most of them are familiar — a few are leftovers from never-shipped features.
Keywords (always reserved)
break | case | catch | class |
const | continue | debugger | default |
delete | do | else | export |
extends | false | finally | for |
function | if | import | in |
instanceof | new | null | return |
super | switch | this | throw |
true | try | typeof | var |
void | while | with | yield |
Contextual keywords (only reserved in certain contexts)
async | await | let | static |
implements | interface | package | private |
protected | public | of | as |
Reserved for the future
These were reserved by older specs but mostly unused: enum, abstract, boolean, byte, char, double, final, float, goto, int, long, native, short, synchronized, throws, transient, volatile.
Not reserved but very confusing
JS
// Legal but evil const undefined = 5; // SHADOWS global undefined — don't do this let NaN = "what"; // same — modern engines actually make NaN read-only // These are NOT reserved words let Infinity = 0; // legal — also evil
Tip: When porting code from Java, Python, etc., watch for
class, const, and private as variable names — they break silently in old browsers and explode in modern ones.Example
Example
<!DOCTYPE html>
<html>
<body>
<p id="out"></p>
<script>
document.getElementById("out").textContent = "Hello from JS Reserved Words!";
</script>
</body>
</html>
Try it Yourself »
Exercise
Which keyword could replace a variable name to cause a syntax error in modern code?
Answer (one word):
Any modern reserved keyword works.
Discussion
Loading…