Skip to main content

Practice ยท 1 of 3

Narrowing Formatter

Write format(value) handling the union string | number | boolean | null | undefined: strings are trimmed then returned, numbers are formatted with exactly 2 decimals, booleans become "yes"/"no", null/undefined become "โ€”".

Difficulty: intermediate

Back to lesson: Practice: Unions & Narrowing โ€” Practice