Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

In this video, the speaker says:

"Some people get confused about how commas work. They think they should be delimiters rather than separators. Now you can think about them either way."

I don't understand the difference between a delimiter and a separator (if there is one). The implication in the video is that now (that trailing commas are valid), one can think of them as delimiters, rather than separators...

Btw the language in question is JavaScript. From my understanding, the comma token has two meanings:

  • as an operator (rarely used)
  • as a separator (in argument and parameter lists, array and object literals, etc.)

I'm not sure how a comma delimiter fits into this...

share|improve this question
Why does this matter? – jfriend00 Dec 30 '11 at 20:40
@jfriend00 If there is a difference between the terms delimiter and separator, I want to know it... I like to know stuff :) – Šime Vidas Dec 30 '11 at 20:44
@jfriend00 Watch the video. If the IE people weren't thinking as narrowly as you, maybe we wouldn't have yet another javascript portability snafu... – Yannis Dec 30 '11 at 20:57
@ŠimeVidas Good question. BTW the speaker is Douglas Crockford, senior JavaScript architect at Yahoo, known for popularizing JSON and author of JavaScript: The Good Parts. It's a good think you pay attention to detail, especially when watching a Crockford video, as he rarely wastes any breath for stuff that don't matter. – Yannis Dec 30 '11 at 21:01
@YannisRizos Yea, I know Crockford. He's a great educator. :) – Šime Vidas Dec 30 '11 at 21:22

2 Answers 2

If you consider the comma as a separator, you use a comma between two items of a sequence to separate them, if you consider it as a delimiter, you put it after each item to indicate where an item ends. See the examples below:

Comma as a separator

var myCars = ["Saab", "Volvo", "BMW" ];

Comma as a delimiter

var myCars = ["Saab", "Volvo", "BMW", ];

I think the video says that you can think of commas both as separators and delimiters because both array examples above are valid. On the other hand in Javascript you can only use the comma as a separator in the parameter list of a function, e.g.

foo(a, b, c) // separator, OK

is valid whereas

foo(a, b, c,) // delimiter, NOT OK!

is not valid.


As far as I understand, according to the wikipedia page a separator is a special case of a delimiter, namely one that is put between the different text regions whose boundaries need to be marked. In fact, the wikipedia page names comma-separated values as an example use of delimiters. So, in general you can use delimiters in different ways: before, after, on both sides of the portion of text to be marked.

The reason why I interpreted delimiter as "marker that is put after an item" in the Javascript context was motivated by the array literal example, which is valid also for C, C++, and Java (I think I have seen at least one question on stack overflow regarding this topic).

Another example of similar but different use of a character is that of semicolon as a statement delimiter (C, C++, Java, Ada, ...) and as a statement separator (Pascal). Therefore

if (a > 0)
    printf("Non positive\n");

is correct C code whereas

IF a > 0 THEN
    WriteLn('Positive'); (* Syntax error here! *)
    WriteLn('Non positive');

is no correct Pascal code.

Maybe terminator would be a better / less ambiguous term than delimiter? E.g. one could formulate the quote as follows: "Some people get confused about how commas work. They think they should be item terminators rather than item separators. Now (in many cases) you can think about them either way."

share|improve this answer
Yes, in parameter lists the comma must be used as a separator, whereas in array literals the comma can either be used as a separator or a delimiter. Or in layman's terms: You can put a comma after the last array element, but you don't have to. – Šime Vidas Dec 30 '11 at 21:19
While your answer does explain the quote from my question quite well, the Wikipedia page for "Delimiter" provides different definitions. According to that article, a delimiter specifies the boundary between regions. So, the "comma as a separator" example from your question above would be called the comma field delimiter, while the "comma as a delimiter" example isn't represented anywhere on that Wiki page. – Šime Vidas Dec 30 '11 at 21:37
@Šime Vidas - Wikipedia is just a reference like any other reference, it's not the only reference. – Michael Riley - AKA Gunny Dec 30 '11 at 22:01
@CapeCodGunny Yes, I'm just pointing out that there are confronting definitions. I would like to see definitions from other references, too. – Šime Vidas Dec 30 '11 at 22:06

A separator would be put between two values, separating them.


A delimiter would delimit a field - it would be on both sides.


When taken this way, it makes little difference, so long as one can extract the separate fields out.

This is a completely different issue to that of usage of a comma in a programming language such as javascript. It is about delimiting/separating values within a string.

share|improve this answer
Ah yes, this makes sense. – Šime Vidas Dec 30 '11 at 20:44
I disagree with your delimiter explanation. Based on your explanation it would be ,one,,two,,three, now the delimiter is on both sides. – Michael Riley - AKA Gunny Dec 30 '11 at 20:58
@CapeCodGunny - You are misinterpreting. The example I gave has a comma before and after each value. The commas not at the very start and end of the string serve as the end delimiter and start delimiter. – Oded Dec 30 '11 at 21:00
@Oded This Wikipedia article provides different definitions. According to it, your first example would be a field delimiter, while your second example isn't represented in that article at all. – Šime Vidas Dec 30 '11 at 21:38
@ŠimeVidas - Fair enough, I was really thinking about a file format like CSV, where commas separate fields, and double quotes (") delimit them. Probably not exactly what Douglas Crockford was talking about. – Oded Dec 31 '11 at 8:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.