0
0
Typescriptprogramming~20 mins

Heterogeneous enums in Typescript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Heterogeneous Enum Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a heterogeneous enum value
What is the output of this TypeScript code snippet?
Typescript
enum Status {
  Ready = 1,
  Waiting = "WAIT",
  Done = 3
}
console.log(Status.Waiting);
Aundefined
B3
C"WAIT"
D1
Attempts:
2 left
💡 Hint
Look at the value assigned to the Waiting member.
Predict Output
intermediate
2:00remaining
Value of enum member with mixed types
Given this heterogeneous enum, what is the value of Status.Done?
Typescript
enum Status {
  Ready = 1,
  Waiting = "WAIT",
  Done = 3
}
const doneValue = Status.Done;
console.log(doneValue);
A3
B"WAIT"
C1
Dundefined
Attempts:
2 left
💡 Hint
Check the explicit value assigned to Done.
Predict Output
advanced
2:00remaining
Reverse mapping behavior of heterogeneous enums
What happens if you try to get the enum key from a string value in a heterogeneous enum?
Typescript
enum Status {
  Ready = 1,
  Waiting = "WAIT",
  Done = 3
}
console.log(Status["WAIT"]);
AThrows a runtime error
B"Waiting"
C1
Dundefined
Attempts:
2 left
💡 Hint
Reverse mapping works only for numeric enum members.
Predict Output
advanced
2:00remaining
Accessing enum keys from numeric values in heterogeneous enums
What is the output of this code?
Typescript
enum Status {
  Ready = 1,
  Waiting = "WAIT",
  Done = 3
}
console.log(Status[3]);
A"Done"
B"Waiting"
C3
Dundefined
Attempts:
2 left
💡 Hint
Reverse mapping works for numeric values.
🧠 Conceptual
expert
3:00remaining
Why are heterogeneous enums discouraged in TypeScript?
Which of the following is the main reason why using heterogeneous enums (mixing string and numeric values) is discouraged in TypeScript?
AThey cause syntax errors during compilation.
BThey break reverse mapping for string members, causing inconsistent behavior.
CThey prevent enums from being used in switch statements.
DThey increase runtime performance overhead significantly.
Attempts:
2 left
💡 Hint
Think about how reverse mapping works in enums.