Void Functions
Void Functions
π¨βπΌ Many functions in real applications don't return valuesβthey perform
actions. These are called side effects, and they return
void.Examples of side effects:
- Logging information
- Updating the UI
- Sending data to a server
- Playing a sound
π¨ Open
and create these exported functions.
Each takes a
message: string and returns void (no useful return value):logInfoβ logs with an[INFO]prefix, e.g.[INFO] Application startedlogErrorβ logs with an[ERROR]prefix, e.g.[ERROR] Connection failedlogWithTimestampβ logs with an ISO timestamp in brackets, e.g.[2024-01-15T12:00:00.000Z] User logged in(use the current time)
Required exports
logInfo, logError, logWithTimestampCompletion criteria
- Each function is callable and returns
undefined(the runtime value ofvoid) - When you call them, console output uses the prefix/timestamp formats above
π° Void functions don't return a valueβannotate the return type as
void.