Reputation: 6431
Using return is valid if code execution is not inside of a function or in the other i am totally on global scope.
var x = y + 1
if(x == 10)
return;//visual studio gives warnings and says that "return keyword is not inside a function"
Upvotes: 1
Views: 66
Reputation: 382177
No it's not. This makes a syntax error if it isn't inside a function.
From the ECMAScript spec :
An ECMAScript program is considered syntactically incorrect if it contains a return statement that is not within a FunctionBody.
Note that some browsers don't follow the spec rigorously :
Upvotes: 3