In JavaScript, if you do not write semicolons ; , they will be inserted seamlessly for you. And you may not always like where they go.
You do not need to technically complete each statement with a semicolon. However, most consider this a good idea.
See our Google search results for more information. We have been discussing this topic for a long time.
Here is an example of why it is more complicated than it seems at first glance. Although you are technically not required to end each statement with a semicolon, there are a few cases where you SHOULD or things break. You cannot completely omit them in most codebases.
foo.def = bar (function() {
Looks simple enough? Well, the interpreter looks at this and does this:
foo.def = bar(function() {
Most likely, this is not what you expected. A way to fix this with a semicolon.
foo.def = bar; (function() {
There are many such cases. You can study them all and use them only in those cases, and when you inevitably forget that you are trying to debug your code doing something so strange and strange that you will rip your hair for several hours ... "what you have in mind wtfvar not a function?!? It should not be a function! "
Or you can just use consistency semicolons.
Alex wayne
source share