Solution: Strict Compiler Options

Review the solutions to the challenges discussed in the previous lesson.

Solution: Assignment error

To fix the assignment error, we need to ensure that the variable a has a value before it is used in the assignment to b. There are two possible solutions:

  • We can directly assign a value to the variable a before using it to initialize b.

  • We can modify the type of a to include undefined using the union operator |. This indicates to the compiler that a can be either a number or undefined.

Get hands-on with 1200+ tech skills courses.