Void

void is another type that doesn't exist in JavaScript. It is generally used to represent a non-returning function.

Let's look at an example:

  1. Let's enter the following function into the TypeScript playground:
function logText(text: string): void {
console.log(text);
}

The function simply logs some text into the console and doesn't return anything. So, we've marked the return type as void.

  1. If we remove the return type annotation and hover over the function name, logText, we'll see that TypeScript has inferred the type to be void:

This saves us a few keystrokes while writing functions that don't return anything.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.83.150