The Ternary Operator vs The Conditional Operator WTF

JavaScript Joel - Aug 31 '18 - - Dev Community

Three Monkeys

Almost a year ago I received a comment on one of my articles.

Its name isn’t “the ternary operator”. It IS a ternary operator

The argument goes on to explain because it is A Ternary Operator, I should refer to it as The Conditional Operator.

This disagreement about language isn't limited to just this one comment thread. I have even seen people correcting others to use A Ternary Operator on top answers on Stack Overflow.

Often called "the ternary operator," but in fact it's just a ternary operator [an operator accepting three operands]. It's the only one JavaScript currently has, though.

Spelling, Grammar and English in general aren't my strong subjects (I do better with 0's and 1's). But, even if I was using the English language incorrectly, I didn't feel like it took anything away from the article. So I had dismissed this as being trivial.

After a fairly lengthy discussion about the grammar. I thought I had made some persuasive arguments. I even referenced some usages of "the ternary operator" in the Mozilla docs. Even so, neither of us were able to come to agreement.

So why am I still thinking about this almost a year later?

My OCD brain wouldn't let this die and I kept thinking about that argument. The other side of the argument was logical. It made sense to me. I understood it. But still, for some unknown reason, I didn't like it. To me it was still The Ternary Operator.

This unresolved discussion left much dissatisfaction in my mind for a number of reasons. First, only one of us can be correct, which means one of us has to be wrong. Second, the correct person (even though correct) has also failed because of their inability to effectively communicate their ideas to the other. Dissatisfaction for both parties.

The Ternary Operator

So here is my argument to persuade everyone once and for all that the correct usage is either The Ternary Operator or The Conditional Operator and it is incorrect to say A Ternary Operator.

First we have to lay out a foundation of facts that we can all agree upon. Without this foundation, it will not be possible to come to an agreement.

Fact 1: JavaScript has a Conditional Operator that is of type Ternary Operator. If there was a Venn diagram, the Conditional Operator would be inside of the Ternary Operator.

Fact 2: JavaScript has exactly one Ternary Operator. In the Venn diagram, The Ternary Operator circle would contain no circles, other than The Conditional Operator circle.

Fact 3: When using A/AN you are referring to one of a collection of items. Examples could be "A Shirt" or "A Dollar".

Fact 4: When using THE you are referring to a specific item and if there is a collection, a specific item of that collection is known and could not be confused for another item. For example there could only be 1 in that collection. Examples could be "The Cat" or "The Car".

So if we can agree on these facts, then it should be clear that THE is the correct usage for The Ternary Operator because JavaScript contains exactly one Ternary Operator.

If JavaScript contained more than one Ternary Operator, then and only then could The Conditional Operator be referred to as A Ternary Operator.

Examples

My house contains only one cat, his name is Mojo. Mojo is of type Cat, like how The Conditional Operator is of type Ternary Operator. So I can also demand "Bring me THE cat" and you will understand. If I had spoke "Bring me A cat", this would cause confusion and you might think I am asking for a cat other than Mojo.

If you are helping me cook, I can say "Get me A container" of which there is more than one to choose from. You pick a Mixing Bowl which is of type Container. But once you place that bowl on the counter I can say "Put the brussel sprouts in THE container" because there is a specific container I am referring to. If there were no containers on the counter, it would be incorrect for me to say "Put the brussel sprouts in THE container" because there are more than one.

"Pass me THE remote". I have multiple remotes in my house, but you damn well know which one I am referring to. So even though there are multiple remotes, a specific remote is in context, allowing me to use THE.

/rant

tl;dr It is correct to refer to JavaScript's Conditional Operator as The Ternary Operator. It is incorrect to use A Ternary Operator a language that doesn't have a singular Ternary Operator.

I have done my absolute best job to put and end to this discussion. Not for your benefit. See I don't care about you at all, I just want to get this dammed loop out of my brain ARG!!! The only way to do so was to write this f'n article.

This was wordy, sure. I know all too well that I have to go into as much detail as humanly possible. That is because I fully expect one of you poindexters (in your best Jerry Lewis voice) to come back with some "Well, in the instance of multiple species of fish it is actually correct to use the plural form Fishes instead of Fish." But please don't. Give my poor little wee brain a break! lol

I do hope you got some enjoyment from my insane ramblings.

Does your brain get hung up on trivial nonsense like this? I would love love love to hear some stories!

Read more of my functional programming-ish articles.

Oh and follow me on the tweety @joelnet

Cheers!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .