Skip to content

Return-Outside-Function

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Cannot use return outside a function definition

return

The return statement ends function execution and specifies a value to be returned to the function caller. If return is used outside a function definition it will throw a SyntaxError.

However in a node.js script a return statement is allowed outside a function as node.js scripts are wrapped in a module function - https://nodejs.org/api/modules.html#modules_the_module_wrapper