Design Patterns · Junior · Question 41 of 75

What's wrong with "magic numbers" like if (status === 3)?

Explanation

A named constant ORDER_STATUS.SHIPPED explains the meaning and changes in one place. In TypeScript, a union of literals or an as const object is even better.

Further reading

Problem with a question

Design Patterns · Junior · question 41

Test yourself

Take the Design Patterns · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz