Although this question has been asked multiple times, I am still struggling to grasp the concept of enums.
Let's consider a simple enum:
export enum Type {
Null,
First,
Second,
Third
}
Now, the query is, what is the difference between these code snippets?
if (myObject.type === 2) doStuff();
And this one:
if (myObject.type === Type.Second) doStuff();
I retrieve myObject
from the backend and need to identify its type to execute specific functions. Why should I use enums in this scenario?
I might be mistaken, but both examples seem to achieve the same outcome.
Could you please clarify why I should incorporate enums in my use case?