TypeScript · Middle · Question 38 of 75

What does the ReadonlyArray<T> utility (or readonly T[]) do?

Explanation

A readonly T[] parameter guarantees the caller that the function won't modify their array. It accepts regular arrays too. The type doesn't prevent changing nested objects - it's shallow protection.

Further reading

Problem with a question

TypeScript · Middle · question 38

Test yourself

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

Take this quiz