void在typescript中是什么意思?
我正在学习打字脚本,在一个教程中遇到了这个switch语句。我知道数字是分配给a的,所以所有参数都应该是数字。但是,虚空意味着什么,它做了什么void在typescript中是什么意思?,typescript,Typescript,我正在学习打字脚本,在一个教程中遇到了这个switch语句。我知道数字是分配给a的,所以所有参数都应该是数字。但是,虚空意味着什么,它做了什么 function switchFunction(a: number): void { switch (a) { case 1: let variableInCase1 = "test"; console.log(variableInCase1);
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);
这意味着函数不需要返回值,这一点在没有
return
语句的事实中很明显。换句话说,该函数只能等同于null
或undefined
如果您希望函数执行操作,然后它将不返回任何内容