I was discussing with a colleague about JavaScript while looking at some snippets. We noticed that these snippets were missing the ;
at the end of the statements. We all know that JS is interpreted correctly even if no semicolon is shown at the end of a line, but I was wondering if this affects somehow the performance of evaluation, since it is an interpreted language.
Semicolons are an essential part of JavaScript code. They are read and used by the compiler to distinguish between separate statements so that statements do not leak into other parts of the code. The good news is that JavaScript includes an automatic semicolon feature.
Nope, in javascript, there is no need to write a ; at the end unless you are writing two lines of code in the same line, such as, console.
A javascript file with spaces, semi-colons and comments is heavier. That's the main impact.
But you're a coder and you have to maintain the code, so this very slight impact is much less important than the adverse one on readability. And omitting the semicolons means you know when you can omit them. But the rules aren't so simple and learning them isn't worth your time.
Leave the semi-colons where they are, you'll avoid bugs.
And use a minifier to build a more concise code for the browser if you want to have the lightest possible code. It's its duty, not yours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With