-2

My code looks like this:

var newVariable = originalVariable?.method1().method2();

What does the "?" do between the originalVariable and the first method?

Orbers
  • 79
  • 6

1 Answers1

-1

The question mark between originalVariable and .method1() acts as a buffer to determine whether originalVariable is NULL.

If orginalVariable is null the methods after the "?" will not be executed.

Orbers
  • 79
  • 6
  • 3
    If you're looking to add a question and answer first make sure there isn't already a question that is a duplicate. – juharr Jun 02 '17 at 21:02
  • Thanks @juharr for the reminder to look for the question that I have before asking it, something I did before creating this one. When searching for my question I didn't use the verbiage that was used in the question I copied and was unable to find it. Perhaps this question will link people using a different vocabulary to that page. – Orbers Jun 02 '17 at 21:20