Why enums are needed
📖 Scenario: Imagine you are building a simple app that tracks the status of orders in a store. Each order can be in one of a few fixed states like Pending, Shipped, or Delivered. You want to keep your code clear and avoid mistakes when using these states.
🎯 Goal: You will create a TypeScript enum to represent order statuses. Then you will use this enum to check and print the status of an order. This helps keep your code easy to read and prevents errors from using wrong status values.
📋 What You'll Learn
Create an enum called
OrderStatus with values Pending, Shipped, and DeliveredCreate a variable called
currentStatus and set it to OrderStatus.PendingWrite an
if statement to check if currentStatus is OrderStatus.ShippedPrint a message showing the current order status using the enum
💡 Why This Matters
🌍 Real World
Enums are used in apps to represent fixed sets of options like order statuses, user roles, or colors.
💼 Career
Understanding enums helps you write safer and clearer code, a skill valued in many programming jobs.
Progress0 / 4 steps