Lesson plan

Elvis operator

In certain computer programming languages, the Elvis operator, often written ?: , is a binary operator that returns the first operand if its value is logically true (according to a language-dependent convention, in other words, a truthy value) or returns its second operand if the first operand is not true. That is, it is a short-circuit OR , which returns its first truthy operand. The syntax of the Elvis operator was inspired by the ternary conditional operator, ? : , since the Elvis operator expression A ?: B is approximately equivalent to the ternary conditional expression A ? A : B . It is called the "Elvis operator" because the notation ?: , when viewed sideways, resembles an emoticon of Elvis Presley with his signature hairstyle. A similar operator is the null coalescing operator, where the boolean truth(iness) check is replaced with a check for non-null instead. This is usually written ?? , and can be seen in languages like C# or Dart.

Back to article

Article summary

In certain computer programming languages, the Elvis operator, often written ?: , is a binary operator that returns the first operand if its value is logically true (according to a language-dependent convention, in other words, a truthy value) or returns its second operand if the first operand is not true. That is, it is a short-circuit OR , which returns its first truthy operand. The syntax of the Elvis operator was inspired by the ternary conditional operator, ? : , since the Elvis operator expression A ?: B is approximately equivalent to the ternary conditional expression A ? A : B . It is called the "Elvis operator" because the notation ?: , when viewed sideways, resembles an emoticon of Elvis Presley with his signature hairstyle. A similar operator is the null coalescing operator, where the boolean truth(iness) check is replaced with a check for non-null instead. This is usually written ?? , and can be seen in languages like C# or Dart.

Key claims

No claims recorded.

Discussion questions

  1. Summarise the article in your own words. Which single claim would you verify first, and why?
  2. Which claim in this article is most likely to be revised as the sources update? How would you check its current status?
  3. If two sources disagreed about one of these facts, what would you need in order to trust one over the other?

Bibliography

No sources recorded.

Key claims and bibliography are generated from the same tracked claims and sources as the article page.