8

I've seen a triple semicolon in a few expressions here and there.
Does it have any logical effect?

The closest thing I've seen for an explanation is that it tells the Dean Edwards compressor to ignore that line.

;;; var someVar = 'Rebel';
brentonstrine
  • 21,694
  • 25
  • 74
  • 120
Chase Wilson
  • 1,477
  • 1
  • 12
  • 19
  • Please post some examples. It could have different meanings in different contexts. – FrustratedWithFormsDesigner Jul 16 '10 at 20:13
  • Code sample? I don't believe it's convention or special syntax that I've ever encountered. – g.d.d.c Jul 16 '10 at 20:13
  • Could you post an example? If I'm not mistaken, `;;;` is equivalent to `;`, since an empty statement does nothing. I'm guessing someone was using `;;;` to section off code or something. Also, make sure the code you're reading is actually JavaScript :-) – Joey Adams Jul 16 '10 at 20:14
  • 3
    Maybe you're thinking of a double semicolon in a for-loop, such as `for (;;) ...` – FrustratedWithFormsDesigner Jul 16 '10 at 20:14
  • You could've at least posted the snippet that you've seen – Darin Dimitrov Jul 16 '10 at 20:15
  • I was reading in some comp.lang.javascript thread where one of the tampons was saying "They could have simply used ;;; in place of ..." I can't remember the exact issue (mainly cause their bitching drowned out all coherence). I couldn't find anything while googling, nor in any of the references I have. I just saw it again in a concatenation of a string. It's just a delimiter on this project though. It just reminded me of the thread. – Chase Wilson Jul 16 '10 at 20:25
  • 13
    It's three eels. Particularly if your `@` is near water (indicated by `}`), you'll want to be very cautious when you see these, unless you're either wearing a greased cloak or robe or a slippery cloak, as they have a drowning attack than can kill you in one round. – Weston C Jul 16 '10 at 20:50

5 Answers5

26

It makes people ask questions on StackOverflow.

Other than that, it does nothing.

Joey Adams
  • 41,996
  • 18
  • 86
  • 115
18

Nothing. Absolutely nothing.

Three semicolons, ten semicolons, a hundred semicolons, they all get interpreted to the same result: nothing.

Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
  • 1
    Let me be known as the guy who got you over 10K rep. :) – ChaosPandion Jul 16 '10 at 20:52
  • 1
    @Gert - I also measure time in nano seconds. :) – ChaosPandion Jul 16 '10 at 20:55
  • Guys, this is the age of quad-core processors. There really isn't much more time required to parse some more freakin' semicolons! Jeez. – Jacob Relkin Jul 16 '10 at 21:00
  • 2
    It's not exactly "nothing"... Multiple semicolons do just the same that one single semicolon, but using no semicolon at all and relying on "automatic semicolon insertion" by the interpreter is a BAD practice. In most cases a carriage return with no semicolon will just work, but in a few cases the results will be unexpected and erroneus. – Sebastián Grignoli Jul 16 '10 at 22:46
  • You say "compile", but Javascript is an interpreted language (natively). It does not get compiled at all. Although who knows what the future holds; the new [V8 engine](http://code.google.com/apis/v8/) actually does compile it to machine code. – Josh Stodola Jul 28 '10 at 17:46
  • @Josh - This assumes they are specifically talking about JavaScript in Mozilla Firefox. This question is implementation agnostic and many will compile the code. *(Take my implementation for example.)* – ChaosPandion Jul 28 '10 at 17:56
  • @Sebastián Grignoli - using no semicolons and relying on the automatic semicolon insertion is fine if you understand the rules that the interpreter uses - and it does follow a strict set of rules so the results are unexpected only to people who don't know the rules. Having said that, I always use semicolons because it is one less thing for me to think about and also then I don't have to worry about other team members who don't know what the auto-insertion rules are. – nnnnnn Nov 28 '11 at 01:52
11

Lines starting with three semicolons are there for debug code: it indicates that those lines should not appear in the production environment. The Javascript is run through a compressor or some other algorithm that removes ;;; lines when creating the optimized JS file.

;;; console.log("only run this line when debugging!");

As indicated above, three semicolons actually does nothing in Javascript: it just ends three consecutive empty statements. If an actual comment was used

// console.log("only run this line when debugging!");

then you'd have to go in and manually remove all comments when you wanted to enter debug mode, and then go in and put them back when you were done. The other solution is to create a DEBUG variable and wrap all debug lines in a condition:

var DEBUG = true;
if(DEBUG){
     console.log("only run this line when debugging!");
}

but this is a little cumbersome and actually adds unneeded code to your Javascript document. Of course you could run the JS through a compressor to remove the DEBUG conditions, but at that point you might as well just use the ;;; method, which is simpler.

See this question for a real life example of this. BTW, I think the syntax comes from emacs.

Community
  • 1
  • 1
brentonstrine
  • 21,694
  • 25
  • 74
  • 120
8

Ends an empty statement 3 times.

Incognito
  • 20,537
  • 15
  • 80
  • 120
  • Hmm, I think we only know about two empty statements. We don't know that the three semicolons aren't following a non-empty statement. – ghoti Oct 15 '12 at 10:54
  • My read of the question was that the code posted was "the Closest thing [he'd] seen", not necessarily one of the examples he has "seen ... here and there". The OP's code is clear about only two empty statements amongst the four semicolons shown. – ghoti Oct 16 '12 at 00:44
  • @user107463 can you comment on this? – Incognito Oct 16 '12 at 01:26
1

They are empty statements and have no effect. It is possible that the interpreter or compiler will remove them unless a statement is required by the syntax.

ChaosPandion
  • 77,506
  • 18
  • 119
  • 157