Exercise 13, questions on semi-colons and modules

Can you give the simple explanation as to why semi-colons aren’t used after the statements of module.exports? For example:

module.exports = {
area: area,
circumference: circumference

Why do we not end these lines with semi-colons as well?


You can, and I think some syntax checkers will require this. I’d say if you’re working on code that does it then go for it, but for me, I find it annoying that I’m adding 2 termination characters. The ; typically is useful because we need to end a syntax and maybe a new line doesn’t do it. In theory it should, but JS is notorious for getting that wrong, so everyone went with ; to make sure a syntax line is ended.

The thing is, once you have } or ] or ) then, well, that syntax is ended. Even if you did ((( )) and then put the final ) on a new line, it’s still clearly done. The ; is pointless, but for consistency a lot of people like to just add them all over. Also, I think people add them “just in case” which ends up being kind of a terrible reason but that’s how it is.


Yeah javascript seems strange in that way. It doesn’t seem to require the ; in all but special cases. I’ve noticed some instructors recently on Udemy leaving it off completely unless it’s needed (which seems rare). Personally I like the look of the code without all the semicolons, but that’s the artist in me wanting to be different, lol.

Well, those instructors are going to get burned in ES6 and beyond. The trend with ECMA is to start making a lot of things syntax errors without ; so you need to basically add them to end lines “just in case”. I really wish they’d just officially go one way or the other with an option, but that’d take way too much wrangling of legacy code.

A free service run by Zed A. Shaw for learncodethehardway.org.