I tend to be a prolific user of semicolons in my JavaScript:
var x = 1;
var y = 2;
if (x==y){do something};
I recently noticed that I was looking at a lot of JavaScript that doesn't have semicolons following if statements. It then occurred to me that I don't even know the preferred syntax for semicolons in JS and after some googling learned (rather surprisingly) that there is no need for semicolons at all aside from splitting statements that are on one line.
So, the question...where did this habit of people using semicolons come from? Is it a remnant from some popular language that was in use at the time JavaScript came into play? Just good practice in general? Is it just me?
I'm probably going to stick with it for no other reason that it's nice when writing jQuery chains to easily spot the end.
UPDATE:
Thanks for all the answers, everyone! It looks like, to summarize things, the reason we see a lot of semicolons in JS even when not needed comes from various variables:
- older JS minimizer's would produce broken code if you did not insert semicolons
- many other languages use them, so it's a carried-over habit
- on occasion, a semicolon CAN change the logic
- some prefer to use them to make the code more human-readable