323
True crime (lemmy.nz)
you are viewing a single comment's thread
view the rest of the comments
[-] Maiq@lemy.lol 6 points 1 year ago

Was looking at it and could not figure out why their weren't any semicolon's.

Neither Javascript nor Typescript require semicolon, it is entirely a stylistic choice except in very rare circumstances that do not come up in normal code.

[-] Ephera@lemmy.ml 2 points 1 year ago

Hmm, a webdev colleague said he'd normally prefer without semicolons, but used them anyways for better compile errors.

Interesting, I'm not aware of any way they would affect compile errors. I'd be curious to know more.

[-] Ephera@lemmy.ml 2 points 1 year ago

I don't have experience with how it affects JavaScript specifically, but independent of programming language, it usually removes the guesswork where the error might be.

The thing is that compilers use fairly static rules for their grammar. So, even if you just typo a comma where there should've been a dot, then its grammar rules don't match anymore and it doesn't really know what to do with your code.
To some degree, it's possible to say certain symbols just cannot appear in a specific place, but especially with a comma, it could be the start of the next element in a list, for example.

Without semicolons, it's likely going to tell you that something's wrong between somewhere before your typo and the next closing brace (}). With semicolons, it can generally pinpoint the specific statement where the comma is wrong.
This should also make analysis quicker while you're editing the code, as it only has to check one statement (or two, if you're inserting a new line and haven't typed the semicolon yet).

load more comments (9 replies)
load more comments (9 replies)
this post was submitted on 14 Aug 2025
323 points (96.3% liked)

Programmer Humor

32979 readers
1224 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 3 years ago
MODERATORS