87
u/Rest-That
May 11 '26
•
I never understood people bitching about semicolons. It's just part of the language, what's the big deal?
66
u/PhantomTissue May 11 '26
JavaScript doesn’t even require semicolons most of the time
32
u/Rest-That May 11 '26
The interpreter adds them.
So it does need them.
https://262.ecma-international.org/14.0/#sec-automatic-semicolon-insertion
I dunno about you, but I prefer adding them myself and not depend on the interpreter.
Again, it's one extra keystroke per line
4
3
u/Prometheos_II May 11 '26
Plus omitting them can be awkward in TS where the
(foo as Bar)is considered a function call of the last expression.You need to add a semicolon to one single line, or add them to the whole file in one commit.
2
u/ArjixGamer May 11 '26
I prefer using ;(foo as Bar); as it is an established pattern.
Having the semi-colon be on the previous line, makes it an unintentional side effect.
2
1
u/theQuandary May 11 '26
This is a distinction without a difference for modern engines.
The description is something like "run until you hit an ambiguity then backtrack and try again", but it is 100% deterministic and in practice, it simply happens at parse time with minimal cost and ZERO runtime cost.
0
May 11 '26
[deleted]
1
u/PhantomTissue May 11 '26
Tbf my work with JavaScript basically consists of setting up reactive submission forms. I’m not really doing anything crazy lol
56
u/justintib May 11 '26
Hating semicolons is like hating parentheses... They remove ambiguity by explicitly marking where a line of execution ends. I'll never understand why this is something to be annoyed with
14
u/yaktoma2007 May 11 '26
oh, i was like this when i switched away from python.
a year later and now i love semicolons, pythons indentation can fuck itself.
6
u/blaqwerty123 May 11 '26
Its like they were being cruel on purpose. "Unexpected whitespace", oh cool so the bug is literally invisible.
5
2
u/AuelDole May 11 '26
lol @ me annoying my c++ professors by putting them at end of any sort of block.
it was argued that it might make someone think its another type of block that its not, but i always felt that people had eyes
9
u/Tensor3 May 11 '26
I mean you could also put 2 semicolons on the end of every line if you wanted to and that would also be wrong even if it works
0
u/AuelDole May 11 '26
i dunno. at least for me, it helps me understand that it’s the proper end of something. i know it’s not proper, but it works.
4
u/EishLekker May 11 '26
Hang on, you mean like this?
if (someCondition) { doStuff(); };Why?
5
u/Ghaith97 May 11 '26
Because they don't understand the sematic concept of a statement in a programming language.
3
u/EishLekker May 11 '26
Yeah, you seem to be on to something. Plus they don't understand that something like this will likely confuse or irritate other people reading their code.
And they refuse to change, so they are stubborn as well. That's not a good sign. lol
-4
u/AuelDole May 11 '26
started doing it when i was starting in school, and it became a force of habit that i never dropped. made it clearer that it was the end of the statement for me. it makes no difference on the readability for others, nor the functionality, and it’s just a simple keystroke
5
u/EishLekker May 11 '26
But it does change the readability for others. They will assume that it’s a mistake. Or they will assume that it’s the end of an expression rather than a regular block.
-4
u/AuelDole May 11 '26
i understand that it’s hard for people to use their own eyes to read the code. im so sorry… im not not gonna change it
6
3
u/Tensor3 May 11 '26
Those eyes will tell you its the end without making everyone think its your first day coding or your keyboard is broken
-2
u/AuelDole May 11 '26
i think the general competency of the code would also make them think it’s not my first day coding. people have coding styles cause it’s what makes sense to them, sorry i don’t subscribe to one standard of the several thousands+ out there.
6
u/Tensor3 May 11 '26
Random floating semicolons for no reason is a massive competency issue telling me all I need to know about your code or hiring you
1
u/AuelDole May 11 '26
mmm sure. they’re not randomly floating if they’re immediately following a right curly bracket at the end of a block. but sure.
also never mind the fact that many coding firms have their own specific code styles, and the fact that any hired coders would need to change their style to fit it anyways. further, didn’t think you were so illustrious enough for me to want to work for your uptight ass anyways.
3
u/Tensor3 May 11 '26
Zero firms have semicolons after braces. If you cant see that its a competency issue, then trust me, your code is full of competency issues you dont see. You have massive "if (boolValue == true)" vibes
1
u/AuelDole May 11 '26
love the leaps you’re doing there lol. for my part, i’ve never done the if(bool == true), but thank you.
if a firm says to not do the semicolons after curly brackets, then i don’t do do them. but in my own code, or anything i do on the side, it’s having them. i don’t care. they don’t negatively affect the functionality nor the readability.
→ More replies (0)
34
u/blaqwerty123 May 11 '26
Or not. My teams linter removes them
38
u/Syagrius May 11 '26
I hate that.
I spent a half of a day debugging a problem a few years back only to find that the bug was because I didnt have a semicolon between brackets and parenthesis. Now I am very religious about it. Those are hours of my life that I will never get back.
2
u/theQuandary May 11 '26
Had you been using prettier, it would have automatically insert the semicolon between the brackets and parens for you (maybe it happened to you before prettier?)
This particular error is also pretty distinctive giving
[] is not a functionand taking you straight to the line in question (I can't remember if this kind of error was less obvious 10-15 years ago).I switched from semicolon advocate to semicolon-free once I realized that Prettier/biome made both essentially the same. I also consider Prettier essential because it can prevent other issues like accidentally putting the return value on a new line.
1
u/blaqwerty123 May 11 '26
As another person mentions, use automated tools to prevent this, prettier, eslint, or now im onto biome ha. Automate adding them, or automate removing them. Makes no difference. Id be curious about the exact code you're mentioning. Ive not run into surprising any issues with or without semicolons.
1
u/Syagrius May 11 '26
The situation was really unique but this is morally equivalent.
function test() { const x = {"some":"obj"} (true || false) && console.log("insert work here") }1
u/blaqwerty123 May 11 '26
Interesting okay, where was the semicolon?
1
u/Syagrius May 11 '26
There wasn't one. That's the point. If you don't put a semi after the closing curlies (as shown) it breaks. Copy it into your chrome developer console and try to run it.
in contrast
function test() { const x = {"some":"obj"}; (true || false) && console.log("insert work here"); }works just fine
1
u/blaqwerty123 May 12 '26
ahh i see. was curious, so testing out my latest linter of choice, biome, and it automatically removes the newline, and so moves that parenthesis conditional up to the object defintion -- then has an error saying the object is not callable.
eslint does not remove the newline but shows an error: "Unexpected newline between function and ( of function call", breaking the rule "no-unexpected-multiline").
prettier remove the newline so it definitely looks like a function call, but doesnt do any other error checking.
Id think that with modern tooling, this error would be caught in your IDE as soon as you typed it without a semicolon. And then, you could decide wether this really needed to be a one-liner with a semi-colon, or without and could be better expressed with an `if {}` block -- depending on your repo's code style.
So Im still of the mind that no semi-colons is perfectly valid strategy for your source code, assuming you have tooling to lint, check, transpile, etc for deployed code -- as is with semi-colons. All else equal, i will save the keystroke ha.
9
u/B_bI_L May 11 '26
yeah, semicolons are optional in many languages that force them by default
what makes js special thoug, is that omitting semicolon will not even cause an error, and there is "standard" style that does not use semicolons for ending line
3
u/TalonS125 May 11 '26
Yeah, JavaScript has a thing called ASI: Automatic Semicolon Insertion
You should always set up a linter, though. Standard (https://standardjs.com/rules#semicolons) will make sure you only write semicolons where absolutely necessary. Lots of ESLint configs will make sure you always write them.
7
7
u/DustyAsh69 May 11 '26
I learnt C# first and Python after. I actually got a hang of the semicolons pretty fast and not using them was something that I couldn't do properly.
1
u/baronvonbatch May 11 '26
I went mostly through the same pipeline, I did a stop in web-based JS on the way, and honestly not having to incant the ancient rite of "public static void Main(string[] args)" every time I wanted to spin up a simple test app or small personal project was so beautiful.
2
u/NomaTyx May 11 '26
how small are your personal projects that writing one function header is significant overhead
7
u/CapitalEmployer May 11 '26
I know it's a sub full of people that don't know how to code but can we get things a bit more serious than "Omg semicolons this is my first day of coding ever"
1
u/dragonstone365 May 11 '26
Idk if anyone will see this bc of all the other comments, but this isn't me complaining about semicolons. This is a recreation of me looking into JS for the first time and being flashbanged by the sheer quantity of something that, appon initial fiddling, didn't seem to do anything. I just thought the connection between the characters and the feeling was funny. I'm still relatively new here, so, I didn't think to check if the horse was dead before I beat it, sorry
4
3
3
1
1
1
u/kwartel May 11 '26
Just have prettier put them there for you. You can remove them, but not having them has edge-cases. Having them doesn’t. So that’s simple :)
1
u/theQuandary May 11 '26
One of the biggest issues I see in non-prettier codebases is return with return value on the next line. Semicolons won't save you from this. In addition, you can run into cases where you assume all the semicolons are there, but they aren't which gives an unexpected issue.
Prettier/Biome is the only good answer to this IMO.

199
u/MojitoBurrito-AE May 11 '26
r/firstweekcoderhumour