this post was submitted on 15 Sep 2023
98 points (69.9% liked)

Programmer Humor

31224 readers
51 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 4 years ago
MODERATORS
 
top 14 comments
sorted by: hot top controversial new old
[–] [email protected] 39 points 9 months ago (3 children)

Wouldn't the IDE pointed it out?

[–] [email protected] 15 points 9 months ago (3 children)

Yes.

Besides, Javascript doesn't need semicolon since 2016.

[–] [email protected] 27 points 9 months ago* (last edited 9 months ago) (1 children)
[–] [email protected] 5 points 9 months ago (1 children)

Wait, did you just made a meme of my comment?

Awesome!

[–] [email protected] 4 points 9 months ago

Glad you take it like a champ :)

[–] [email protected] 13 points 9 months ago* (last edited 9 months ago) (2 children)

Automatic Semicolon Insertion (ASI) has (sadly) been a part of JavaScript longer than 2016. I'm not sure exactly when it was introduced, but this document from 2009 already contains it: https://web.archive.org/web/20120418215856/https://ecma262-5.com/ELS5_Section_7.htm#Section_7.9

IMO it's bad practice to rely on ASI since the semicolons may not get inserted where you expected them to. The following snippet

const x = 0
const y = x
[1, 2, 3].forEach(console.log) 

is interpreted as

const x = 0;
const y = x[1, 2, 3].forEach(console.log);

which raises a TypeError.

There are more examples of ASI not doing the right thing on the web, so I don't agree with "Javascript doesn't need semicolon".

[–] [email protected] 3 points 9 months ago

As Mark Twain said, “Never discuss politics, semicolons, tabs, or religion in polite company.”

[–] [email protected] 1 points 9 months ago

Use an autoformatter for all code (both in the editor on save/type and as CI check).

There is no problem anymore.

[–] [email protected] 2 points 9 months ago

Javascript doesn't need semicolons in the same way it doesn't need indentation. Great feature for when you're minifying code, but can easily lead to weird bugs.

[–] [email protected] 7 points 9 months ago

Only someone who is really into mental torture would not use a linter.

[–] [email protected] 1 points 9 months ago

Obviously, you patch the IDE so it doesn't

[–] [email protected] 21 points 9 months ago (1 children)

The IDE will tell you and fix it for you.

[–] [email protected] 4 points 9 months ago

Not if they use GNU nano or that shitty windows notepad.

[–] [email protected] 4 points 9 months ago

Jokes on them I don’t use semicolons in JavaScript