Lesson 18 of 55
15 mins readPython Void vs Undefined vs Never in Functions
In Plain English
Understand the distinct semantics of void (caller ignores any return value), undefined (function explicitly returns undefined), and never (function never returns or halts program execution).
Core Rules to Remember

void: Indicates no returned value is expected or used by caller.

never: Indicates the function throws an exception or enters an infinite loop.
Live Interactive Example
Hit Run Code to see it liveContrasting Void, Undefined, and Never
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Output Console
Click "Run Code" to view the rendered output.
How it works: void allows callbacks to return values that callers simply ignore, while never asserts unreachable control flow.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Assert Exhaustive Failure with Never
Write function assertUnreachable(x: never): never that throws new Error(`Unexpected value: ${x}`).
Wrap a call in try/catch passing "corrupt_state" as never and print the caught error message.
1
2
3
4
5
6
7
8
9
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.