TypeScript · Junior · Question 66 of 75

What is the type of const port = env.PORT ?? 3000 if env.PORT: string | undefined?

Explanation

?? removes undefined/null from the left side and adds the type of the right side. Convert with Number(...) if you need a number.

Further reading

Problem with a question

TypeScript · Junior · question 66

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