0

I am a C ++ programmer (not very good), and I know what enum is. When I was reading about lexical grammar (Source MDN), I saw a new keyword, enum. I tried it on NodeJS. And it works! (Well yes, but actually no ...).

enum someEnum {
 
}

And NodeJS throws an error...

SyntaxError: Unexpected reserved word
←[90m at wrapSafe (internal/modules/cjs/loader.js:1060:16)←[39m
←[90m at Module._compile (internal/modules/cjs/loader.js:1108:27)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1164:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:993:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:892:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m

But look! NodeJS considers it a keyword. The question is, is there a right way?

asked Aug 3, 2020 at 4:02
1
  • 1
    enum doesn't do anything currently. It's just a reserved keyword for the futuer. Commented Aug 3, 2020 at 4:03

2 Answers 2

2

As said in the MDN source you linked, enum has been reserved for future use, but the functionality has not been implemented yet. You can either use the enum package, or use something like Typescript that does implement enums.

answered Aug 3, 2020 at 4:07
Sign up to request clarification or add additional context in comments.

Comments

1

If you notice, its section is Future Reserved Keywords, which

They have no special functionality at present, but they might at some future time, so they cannot be used as identifiers.

Currently, enum is supported in JS's superset, Typescript

answered Aug 3, 2020 at 4:08

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.