Error AtlasError Documentation and Resolution

JavaScript return statement is outside a function

SyntaxError: return not in function

JavaScript found a return statement where function return semantics do not apply, such as top-level script code.

SyntaxError: return not in functionsyntax
SyntaxError: return not in function
  • A return statement is placed at top level in a script.
  • Braces or block structure caused the return to fall outside the intended function.
  • Code was copied from a function body into a non-function context.
  1. Move the return statement inside a function body.
  2. Check surrounding braces and indentation to confirm the actual scope.
  3. Refactor top-level logic so it does not rely on return outside a function.
MDN: SyntaxError: return not in function
JavaScript return not in function: causes and fixes | Error Atlas