3

I have found this piece of code in on example:

const value: Token | undefined = object?.token

What this part "object?.token" actually means?

I cannot find it online, I am not sure how to search for it.

I understand that object.token is used to access token property of object, but what is the use of "?"

Thanks

0

1 Answer 1

3

This is called Optional Chaining in Typescript.

Optional chaining lets us write code where TypeScript can immediately stop running some expressions if we run into a null or undefined.

For your example if object is not null and undefined get the value of property token.

See this

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.