TypeScript Readonly and Immutability Quiz
A 30-question TypeScript quiz covering readonly properties, immutable arrays and tuples, const behavior, structural immutability, shallow freezing, and readonly utility types.
Question 1
What does the readonly modifier prevent?
Question 2
Readonly affects:
Question 3
Why does this error?
const user = { name: 'A', age: 20 } as const;
user.age = 30;Question 4
What does readonly not guarantee?
Question 5
Why is push not allowed?
const nums: readonly number[] = [1, 2, 3];
nums.push(4);Question 6
Which statement is true about readonly tuples?
Question 7
What type is inferred here?
const coord = [10, 20] as const;Question 8
ReadonlyArray<T> prevents:
Question 9
What does const prevent?
Question 10
Which statement is true?
Question 11
What does Readonly<T> do?
type User = { name: string; age: number };
type RU = Readonly<User>;Question 12
ReadonlyArray<T> is equivalent to:
Question 13
Immutability encourages:
Question 14
Which operation is allowed?
const settings: Readonly<{ dark: boolean }> = { dark: true };Question 15
Which is a benefit of immutable data?
Question 16
Why is this allowed?
const obj = { inner: { x: 1 } } as const;
obj.inner.x = 2;Question 17
Readonly<T> creates:
Question 18
What does Object.freeze do at runtime?
const data = Object.freeze({ a: 1 });Question 19
Which limitation does Object.freeze have?
Question 20
Why can't arr[0] be reassigned?
const arr: readonly [string, number] = ['x', 10];
arr[0] = 'y';Question 21
Immutability helps avoid:
Question 22
Why is assignment invalid?
class Point {
readonly x: number;
constructor() { this.x = 5; }
}
const p = new Point();
p.x = 10;Question 23
Readonly in classes ensures:
Question 24
What is a recommended immutability pattern?
Question 25
Readonly applies primarily to:
Question 26
Immutable structures often lead to:
Question 27
Which is NOT a feature of readonly?
Question 28
Which syntax makes an array deeply readonly?
Question 29
Readonly is helpful in large projects because:
Question 30
Overall, readonly helps developers:
