Professional developer for twenty years. Team lead, technical lead.
What I love is to code stuff. I appreciate pair programming. I think software design is important. I also love to debug code.
The Elvis operator ?: returns left-hand side if it is trueish, right-hand side otherwise, thus comparable to object || default. groovy-lang.org/operators.html#_el...
It is called Elvis because it looks like an Elvis emoticon, but I always memoized it with "Not sure if he still exists" :-)
king?:sing()
OTOH, the safe-navigation operator ?. will return left-hand side if it is null, otherwise evaluate right-hand side on the result of left-hand side, thus comparable to object && object.propgroovy-lang.org/operators.html#_sa...
So the proposal for JavaScript is not the Elvis operator, but comparable to the safe-navigation operator.
Indeed! Yes, thanks for the correction. In my new blog post, I talk about the Elvis Operator and hopefully others won't make the same confusion as I had 😅
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hahaha, I think I learned something new! Never knew that was called the ‘elvis’ operator 😂
I first heard it referred to as that when I was reading through a groovy scripting tutorial!
The Elvis operator
?:
returns left-hand side if it is trueish, right-hand side otherwise, thus comparable toobject || default
. groovy-lang.org/operators.html#_el...It is called Elvis because it looks like an Elvis emoticon, but I always memoized it with "Not sure if he still exists" :-)
OTOH, the safe-navigation operator
?.
will return left-hand side if it is null, otherwise evaluate right-hand side on the result of left-hand side, thus comparable toobject && object.prop
groovy-lang.org/operators.html#_sa...So the proposal for JavaScript is not the Elvis operator, but comparable to the safe-navigation operator.
Indeed! Yes, thanks for the correction. In my new blog post, I talk about the Elvis Operator and hopefully others won't make the same confusion as I had 😅