142
Elvis
(feddit.it)
Post funny things about programming here! (Or just rant about your favourite programming language.)
why would you call it anything other than the ternary operator
Because it's not one. Ternary operator is A ? B : C, Elvis operator is A ?: B. The same two characters are involved, but both the syntax and effect is different.
The second one isn't valid syntax in any programming language I'm familiar with. What does it do?
It's a shorthand for writing this:
This is equivalent:
Huh. Neat feature.
It's in Kotlin and some other languages. C# has it but there it's actually
A ?? B
.Read further down on my other comment to understand, it's just how the operator looks