I was trying to declare a variable named enum
but got Uncaught SyntaxError: Unexpected reserved word
error.
I'm not using typescript, so why is enum
a reserved keyword?
I was searching for it and realized that enum
is a reserved keyword, but protected
is also reserved and doesn't give me the error.
I also couldn't find what enum
is used for or how it works in vanilla js.
I was trying to declare a variable named enum
but got Uncaught SyntaxError: Unexpected reserved word
error.
I'm not using typescript, so why is enum
a reserved keyword?
I was searching for it and realized that enum
is a reserved keyword, but protected
is also reserved and doesn't give me the error.
I also couldn't find what enum
is used for or how it works in vanilla js.
- 6 Documentation: developer.mozilla/en-US/docs/Web/JavaScript/Reference/… and the text says: "The following are reserved as future keywords by the ECMAScript specification. They have no special functionality at present, but they might at some future time, so they cannot be used as identifiers." – epascarello Commented Jan 24, 2020 at 18:10
- 6 Why not? It's used in many languages, so ECMAScript reserved it for future possible use, so that people don't start using it all over their code, making it impossible for them to use it later. – Heretic Monkey Commented Jan 24, 2020 at 18:10
-
4
protected
is only reserved in strict mode – some Commented Jan 24, 2020 at 18:12 - @epascarello Thanks, now it makes sense. That is what I needed – Vencovsky Commented Jan 24, 2020 at 18:12
-
Note that since Javascript is very case-sensitive, you could still use
Enum
as it is not reserved. – Trashman Commented Apr 7, 2022 at 19:47
1 Answer
Reset to default 10According to the docs
The following are reserved as future keywords by the ECMAScript specification. They have no special functionality at present, but they might at some future time, so they cannot be used as identifiers.
And enum
is always reserved keyword.