Enumerations (Enums) are a common data structure feature in many programming languages. While JavaScript does not natively have this feature, we ca...
For further actions, you may consider blocking this person and/or reporting abuse
Hi Steve Griffith,
thank you for your article.
I like how you switch from arrays to enums because I think it makes it easier to understand.
I'm not sure if that's intentional, but I also like the touch of humor found in your article.
Overall, I think the article is good enough to fit into an MDN documentation :D.
That was exactly my intent with the arrays.
Thanks for the hint with Object.freeze() when creating enum πͺ
A well-written explanation. Thank your for sharing !!
Great article thanks
Thanks for the article Griffith.
I needed enums for my library project, your article helped me figure it out. Thanks
Thanks for sharing. Most concise and easily understandable explanation Iβve seenβ¦
I would prefer Errortype.DATA_ERROR.
:) You can call them whatever you like.
I usually prefer the dot syntax too.
The valuable thing is having strings for names, instead of numbers, plus names and values that cannot be altered.
You can but you shouldn't, naming counts.
:D
Very true.
Why not just use TypeScript which has built-in enums and many more goodies.
Because a lot more people use JavaScript, not Typescript when developing.
When Typescript compiles back into JS, this is what it is doing.
Map δΈι¦εοΌ
Maps have the same problem as objects - they can be altered. Object.freeze( ) gives the best version of an enum.