Search code examples
coffeescriptoperators

The ?. operator in languages besides CoffeeScript


I've seen the use of ?. operator in an article on CoffeeScript:

e.dataTransfer?.types?.contains 'Files'

which is equivalent to JavaScript's

e.dataTransfer && e.dataTransfer.types && e.dataTransfer.types.contains('Files')

Is there a name for such operator, and does it exist in other languages?


Solution

  • Sometimes it is called "Safe navigation" operator, it is presented in Groovy: http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator