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 go...
For further actions, you may consider blocking this person and/or reporting abuse
Tldr:
The conditional operator (
?:
) is a ternary operator, and the addition operator (+
) is a binary operator.As the conditional operator is the only ternary operator, people usually refer to it as
the ternary operator
, but that isn't completely true.Correct (mostly).
While The Conditional Operator's name is not The Ternary Operator, it is however correct to reference it by it's type as The Ternary Operator. The difference being one you are calling by name and one by type.
So in the end it doesn't matter what you'd call it until someone comes up with another ternary operator.
Maybe you should call it the ternary conditional operator :D
console.write(post.author === 'joelnet' ? 'You are correct' : 'BZZZZZT!')
>You are correct
I could see the verbiage "a ternary operator" if you're trying to get across that you're not limited to one per statement / function / module / etc., but until they define another one,
?
is the ternary operator.Now I am curious about what a second ternary operator would do...
It does seem that you really only need one, as others could be expressed in terms of the first. I actually gave this probably more thought than I should have, but the only things I could come up with were not conditional operators; they were more combinations of prefix/postfix/infix operators.
I'm guilty of using 'a ternary operator' more than once.
In my defense it happens because when we have a couple of appearances of the ternary operator in an algorithm and then I want the other person to add another, I think it is more practical to say "add a ternary over there" instead of "add the ternary operator" because it could happen that the other person things I'm referring to a previous one.
I think that is correct English when used this way. Because you could also say "add a conditional operator over there".
Maybe someone with an English degree can explaining these rules :)
Ternary,+ operators are syntax sugar. The if-expression is the only one common enough to be present in most languages though.
In python: 1 < 2 < 3 or 1 < 2 < 3 < 4 expands to 1 < 2 and 2 < 3 ...
In haskell you can sort of write your own operators with n-ary syntax.
Macros also can provide n-ary syntax. React would be an example of this in Javascript+jsx.
And now you triggered 100 more OCD brains, damn you.
you should know full well that it couldn't be helped :D
You brung us back to school 🏫 with this one! 😂
I've always called it a "ternary expression" 😭
I tend to refer to the usage of that operator as ‘an inline conditional’. But as long as everybody understands (i.e. there is little or no room for misunderstandings) it doesn’t matter that much.
That's the truth!