Void and undefined
Similarity
function testFn(): void {
}
function testFn2(): undefined {
}
console.log(testFn()); // undefinedBoth cases are accepted, since if no return value is specified , javascript will return undefined
Difference
A contextual function type with a
voidreturn type (type voidFunc = () => void), when implemented, can return any other value, but it will be ignored.

When a literal function definition has a
voidreturn type, that function must not return anything.

Last updated
Was this helpful?