return
{
foo: 7
};
still returns undefined.I was really explaining why rookies will make mistakes with js. The simplest way to prevent those types of errors is to always use ; and to use { on the same line style.
I think my new pet-peeve is the word "clean". What you mean, when you say that, is that it looks good, according to your taste. That's a rather subjective statement, disguised as an objective one.
(end of rant)
I wasn't suggesting that languages that don't have semicolons look ugly or unclean. I do a lot of assembly language but obviously there is no real issue there with semicolon/line endings, since the convention is to write a single instruction per line.
Also, I don't understand how adding a semicolon could help against the "stupid error" you cite. Could anyone please explain ?
If you always put semicolons to mark the end of a statement, then seeing a statement without one would be like seeing a megablocks brick in your lego box - glaringly obvious and extremely offensive.
IMHO that backeting style sucks, and shouldn't be used, at least in js.
I am certainly not against coding practices or readability. With (Q)BASIC, you could also add semicolons and have multiple statements per line, but who did ? It seems that it is the same with Javascript, semicolons are separators between statements, as well as newlines : why write both ? just to be sure they are well separated ?
Why force yourself to remember edge cases, when you can just remove that whole class of bugs by being explicit about what you mean...
I remember when I first saw C code (coming from BASIC) and thought similar thoughts - eugh what are all those useless semicolons they don't do anything what's the point of them etc.
One important point is that it allows you to rearrange the whitespace in your code, without changing the execution meaning of your code. Which is pretty useful in making your code beautiful and readable and avoiding bugs.