0

I have a TypeScript code snippet that contains the following statement row?.delete();.

I was wondering what does the question mark symbolize?

What would happen in case row was null?

Thanks!

Aayush Gupta
  • 41
  • 1
  • 9
  • 1
    Also: [Null-safe property access (and conditional assignment) in ES6/2015](https://stackoverflow.com/q/32139078) – VLAZ Oct 04 '20 at 08:51

1 Answers1

0

This operator is called optional chaining. What it does is first checks if the row is defined and then tries to access the delete.

In case row is null this row?.delete() will just return undefined.If you used it without this operator like row.delete() and row was null you would get Uncaught Type Error: Cannot read property 'row' of undefined.

For more details and examples you can check here https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html