Categories
JavaScript Answers

How to fix Syntax error: Illegal return statement in JavaScript?

Spread the love

Sometimes, we want to fix Syntax error: Illegal return statement in JavaScript.

In this article, we’ll look at how to fix Syntax error: Illegal return statement in JavaScript.

How to fix Syntax error: Illegal return statement in JavaScript?

To fix Syntax error: Illegal return statement in JavaScript, we should use return only in functions.

For instance, we write

const myFunction = () => {
  //...
  return myThing;
};

to define the myFunction function.

And in it, we return the myThing variable.

Conclusion

To fix Syntax error: Illegal return statement in JavaScript, we should use return only in functions.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *