readonly and Optional Properties
readonly stops reassignment after creation. Optional properties may be missing.
Example
interface Config { readonly host: string; port?: number }
const c: Config = { host: "localhost" };
console.log(c.host, c.port ?? 80);Result
localhost 80
Exercise
Cannot change.
host: stringQuiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.