A. Cannot assign to 'url' because it is a readonly property
B. Missing semicolon after interface declaration
C. Type mismatch: string assigned to readonly property
D. Interface properties cannot be initialized
Solution
Step 1: Identify the readonly property usage
The property url is marked readonly, so it cannot be reassigned after initialization.
Step 2: Check the assignment line
The line config.url = "https://newapi.com"; tries to change a readonly property, causing a compile-time error.
Final Answer:
Cannot assign to 'url' because it is a readonly property -> Option A
Quick Check:
Readonly properties cannot be reassigned [OK]
Hint: Readonly properties cause errors if reassigned [OK]
Common Mistakes:
Ignoring readonly and trying to reassign
Confusing readonly with optional properties
Thinking semicolon or type is the error
5.
You want to create an interface Person with a readonly id and a mutable name. Which code correctly enforces this?
?
hard
A. interface Person { id: readonly number; name: string; }
B. interface Person { readonly id: number; name: string; }
C. interface Person { readonly id: number; readonly name: string; }
D. interface Person { id: number; name: readonly string; }
Solution
Step 1: Define readonly and mutable properties correctly
The readonly keyword must be before the property name to make it immutable; properties without it remain mutable.
Step 2: Evaluate each option
interface Person { readonly id: number; name: string; } correctly marks id as readonly and name as mutable. Options B, C, and D misuse readonly or make both properties readonly.
Final Answer:
interface Person { readonly id: number; name: string; } -> Option B
Quick Check:
Readonly before property name only for immutable fields [OK]
Hint: Put readonly before only the properties you want fixed [OK]
Common Mistakes:
Placing readonly after property name or type
Making all properties readonly by mistake
Confusing readonly with type annotations
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.