The JavaScript exception "return not in function" occurs when a return
statement is called outside of a function.
SyntaxError: Illegal return statement (V8-based) SyntaxError: return not in function (Firefox) SyntaxError: Return statements are only valid inside functions. (Safari)Error type 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.
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:
function cheer(score) {
if (score === 147) {
return "Maximum!";
}
if (score > 100) {
return "Century!";
}
}
See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4