Returning nothing with Void
In this lesson, you will learn how to explicitly mention something that does nothing.
We'll cover the following...
Void means nothing. However, undefined
can be assigned to void
. The operation of setting undefined
to void
is not useful per se. However, a function that returns nothing should be marked with the reserved void
keyword.
Press + to interact
function executeFunctionWithoutReturnType(): void {return undefined;}let returnType = executeFunctionWithoutReturnType(); // Hover the variable to see "void"console.log(returnType);
If a function is not explicitly marked with void as the return value, then by ...