It is used to avoid sequential explicit null checks and assignments and replace them with method/property chaining.
leads to an error if applied to a null object, the safe navigation operator stops the evaluation of a method/field chain and returns null as the value of the chain expression.
It was first used by Groovy 1.0 in 2007[1] and is currently supported in languages such as C#,[2] Swift,[3] TypeScript,[4] Ruby,[5] Kotlin,[6] Rust,[7] JavaScript,[8] and others.
[], the null-conditional element access operator, which performs a null-safe call of an indexer get accessor.
Note that an IndexOutOfRangeException is still thrown if the array is non-null but empty (i.e. zero-length).
Existential operator:[12] Crystal supports the try safe navigation method [13]
[18] It short-circuits the whole chain of calls on its right-hand side: in the following example, bar is not "accessed".
Perl 5 does not have this kind of operator, but a proposal for inclusion was accepted with the following syntax:[19] The null safe operator was accepted for PHP 8:[20] Safe method call:[21] Ruby supports the &.
operator on the nullable value instead: The entire expression is null if one of ?