Solution: Strict Compiler Options
Review the solutions to the challenges discussed in the previous lesson.
We'll cover the following
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 initializeb
. -
We can modify the type of a to include
undefined
using the union operator|
. This indicates to the compiler that a can be either anumber
orundefined
.
Get hands-on with 1400+ tech skills courses.