Google News
logo
TypeScript - Interview Questions
What is void, and when to use the void type?
The void indicates the absence of type on a variable. It acts as the opposite type to any. It is especially useful in functions that don’t return a value.
function notify(): void {
  alert("The user has been notified.");
}
If a variable is of type void, you can only assign the null or undefined values to that variable.
Advertisement