Our volunteers haven't translated this article into বাংলা (বাংলাদেশ) yet. Join us and help get the job done!
You can also read the article in English (US).

Message

SyntaxError: return not in function
SyntaxError: yield not in function

Error type

SyntaxError.

What went wrong?

A return or yield statement is called outside of a function. Maybe there are missing curly brackets somewhere? The return and yield statements must be in a function, because they end (or pause and resume) function execution and specify a value to be returned to the function caller.

Examples

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

// SyntaxError: return not in function

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

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

See also

ডকুমেন্ট ট্যাগ এবং অবদানকারী

ট্যাগ: 
Contributors to this page: nmve, fscholz, lewisje
সর্বশেষ হালনাগাদ করেছেন: nmve,