In defining a function, the last type specifies the type of value that it returns.
You might be wondering why this is necessary.
function test(msg: string): void {
console.log(msg);
}
This particular function doesn't return anything.
let myVar: void = test("hello!");
console.log(myVar);
When you try to assign a value to myVar, it will be undefined
because the function has no return value. This concept is illustrated in this example from Typescript.
let unusable: void = undefined;
So what does "return" mean? It refers to the data that a function sends back after being executed. For example:
function idk(): string {
return "Hello World!";
}
When I call this function, it returns a string.
let myVar: string = idk();
console.log(myVar);
You can learn more about the concept of returning values in functions from this documentation on returning values by MDN.