Created
August 22, 2012 03:01
-
-
Save getify/3421868 to your computer and use it in GitHub Desktop.
`return` syntax errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // i understand THAT javascript doesn't assume a `;` before `return` in | |
| // these examples. but i don't understand WHY it can't? why didn't they | |
| // say that the grammar for `return` always assumes the previous statement | |
| // is complete? | |
| // NOTE: david baron pointed out that `if(a)return;` definitely wouldn't want | |
| // to have this assumption. good point. but the others? | |
| // NOTE: assume all these are inside a function, so `return` is safe. | |
| // illegal | |
| var a=""return; | |
| var a;a=""return; | |
| var a;a={}return; | |
| var a;(a="")return; | |
| var a;[a=""]return; | |
| var a;a=[]return; | |
| // legal | |
| var a;{a=""}return; | |
| if(a){}return; | |
| for(var a=0; a<1; a++){}return; | |
| function a(){}return; | |
| switch(a){}return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like all statements:
(but that still doesn't answer why)