void The void Type

Last updated: 2026-10-22

void The void Type

void means "no meaningful return value". Use it for loggers and event callbacks to tell callers not to expect a result.

GroupBasic Types
KindType
Strict modeNot required

ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.

📝 Syntax

function log(msg: string): void {
  console.log(msg);
}
type Handler = (event: string) => void;

⚙️ Parameters

() => voidvoid in a callback's return position: implementations may return values, callers ignore them

Returns:void is itself the return type: annotated functions have no meaningful result; under strict, using their return value yields void.

▶ Example

Edit the code below and click Try it to see the transpiled result:

Output:

[event] click
[warn] low battery

(Runtime output after transpilation; writing return 5 inside logEvent is a compile error)

💡 Notes

ℹ️ Info void functions allow bare return; and return undefined, but not returning other values.
💡 Tip Typing event callbacks as (e: Event) => void is standard: implementations may return anything without breaking the contract.
⚠️ Note void differs from undefined: undefined is a real value type, void is an intent declaration — do not mix them.
More cases coming soon.

📚 Related tutorials

❓ FAQ

Q void vs undefined as a return type?
A () => undefined requires explicitly returning undefined; () => void just states "no usable result" and is freer. Callbacks normally use void.
Q Can I assign a void function's result to a variable?
A Syntactically yes (the variable becomes void), but it is just undefined and pointless. Avoid it under strict.
Q What does Promise<void> mean?
A The promise fulfills without data — the async op only signals completion (e.g. a save). Data-fetching APIs should be Promise<T>.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏