Reputation: 1155
I am learning typescript, and I came across this switch statement in a tutorial. I know that number is assigned to a, so all parameters should be numbers. But, what does void mean and do?
function switchFunction(a: number): void {
switch (a) {
case 1:
let variableInCase1 = "test";
console.log(variableInCase1);
break;
case 2:
let variableInCase2 = "test2";
console.log(variableInCase2);
break;
default:
console.log("Default");
}
}
switchFunction(1);
switchFunction(2);
switchFunction(3);
Upvotes: 0
Views: 34
Reputation: 870
It means that the function is not expecting a return value, evident in the fact that there is no return
statement. In other words, the function can only equate to null
or undefined
.
https://www.typescriptlang.org/docs/handbook/basic-types.html#void
Upvotes: 1