TypeScript · Junior · Question 26 of 75

What does the ! operator do in user!.name?

Explanation

A non-null assertion removes null | undefined from the type. If the value is null after all, you get a runtime error. Safer options are an explicit check or user?.name (optional chaining, returns undefined).

Further reading

Problem with a question

TypeScript · Junior · question 26

Test yourself

Take the TypeScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz