Re:Ask HN: Why use semicolons to terminate statements in mod...
by timknauf on Monday November 24, 2008 @08:54AM
(#374797)
Okay, putting all talk of practicality (interpreters, minifiers, convention) aside, let's look at the language itself for a bit; this could lead to some interesting discussion.
JavaScript has two ways of designating the end of a statement. Here is (1):
;\n
And here is (2):
\n
Now, the semicolon can't help you if you type:
return\n
{a:1\n
b:2};\n
because statement end (2) has already kicked in, and so the code will return undefined.
So, given that statement end (2) is part of the standard (and doesn't look like leaving it anytime soon), is there any language reason to use statement end (1)? Is it purely a visual signifier? If so, is that useful to a majority of coders? Am I in a minority for considering it visual noise? Remember, we're putting aside practicalities like existing conventions, minifier capabilities and browser implementations for the sake of the exercise.
JavaScript has two ways of designating the end of a statement. Here is (1):
And here is (2): Now, the semicolon can't help you if you type: because statement end (2) has already kicked in, and so the code will return undefined.So, given that statement end (2) is part of the standard (and doesn't look like leaving it anytime soon), is there any language reason to use statement end (1)? Is it purely a visual signifier? If so, is that useful to a majority of coders? Am I in a minority for considering it visual noise? Remember, we're putting aside practicalities like existing conventions, minifier capabilities and browser implementations for the sake of the exercise.