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.