pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Bad_return

he JavaScript exception "return not in function" occurs when a return statement is called outside of a function." />

SyntaxError: return not in function

The JavaScript exception "return not in function" occurs when a return statement is called outside of a function.

Message

SyntaxError: Illegal return statement (V8-based)
SyntaxError: return not in function (Firefox)
SyntaxError: Return statements are only valid inside functions. (Safari)

Error type

SyntaxError.

What went wrong?

A return statement is called outside of a function. Maybe there are missing curly braces somewhere? The return statement must be in a function, because it ends function execution and specifies a value to be returned to the function caller.

Examples

Missing curly braces

js
function cheer(score) {
  if (score === 147)
    return "Maximum!";
  }
  if (score > 100) {
    return "Century!";
  }
}

// SyntaxError: return not in function

The curly braces look correct at a first glance, but this code snippet is missing a { after the first if statement. Correct would be:

js
function cheer(score) {
  if (score === 147) {
    return "Maximum!";
  }
  if (score > 100) {
    return "Century!";
  }
}

See also

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy