Undefined Versus Null

In this lesson, you will see the ubiquitous type undefined, which is used to define something that does not exist.

undefined

A variable declared but not initialized is undefined. Undefined is not quite the same as the type null. In both cases, an assignment can set undefined or null to a variable explicitly. The following code does not compile because the variable is consumed before initialization and TypeScript when configured to be strict, does not allow for interaction with an unassigned variable.

Get hands-on with 1300+ tech skills courses.