Skip to content

Return-Outside-Function

Sourcery rule id: return-outside-function

Description

Cannot use return outside a function definition

Match

return

Explanation

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