Skip to content
Chapter 2Lesson 8

Quiz - Functions, naming, and control flow

Quiz progress

0 / 0

You’re writing a helper that’s used by code earlier in the same module, and a separate type predicate isInvoice(x: unknown): x is Invoice. Which forms does a 2026 senior reach for?

Both as const arrow expressions — arrow is the default, no exceptions.
The earlier-used helper as a function declaration (hoisting trigger); the type predicate as a function declaration (signature trigger).
The earlier-used helper as an arrow; the type predicate as a function expression assigned to const.

What does this snippet print?

const list = (page: number = 1, size: number = 20) =>
console.log(`p=${page} s=${size}`);
list(undefined, 0);
list(null as unknown as number, 10);
p=1 s=20 then p=1 s=10
p=1 s=0 then p=null s=10
p=1 s=0 then p=1 s=10

Which of these names violate the “name for intent, not implementation” principle? Select all that apply.

customerArray
pendingInvoices
notDisabled
data

Under noFallthroughCasesInSwitch with the discriminated union type Payment = { status: 'pending' } | { status: 'paid' } | { status: 'failed' }, which switch compiles?

switch (p.status) {
case 'pending':
log('p');
case 'paid':
return 'paid';
case 'failed':
return 'failed';
default:
return assertNever(p);
}
switch (p.status) {
case 'pending':
return 'p';
case 'paid':
return 'paid';
default:
return assertNever(p);
}
switch (p.status) {
case 'pending':
throw new Error('pending');
case 'paid':
return 'paid';
case 'failed':
return 'failed';
default:
return assertNever(p);
}

A teammate writes const pageSize = input.pageSize || 20 and const city = user?.profile.address.city. Which fixes does a 2026 senior land in review? Select all that apply.

Change || to ?? so that a caller passing pageSize: 0 (meaning “show no rows”) isn’t silently swapped for 20.
Add ?. at every nullable link — user?.profile?.address?.city — because each ?. only guards the one access to its left.
Leave || alone; in TypeScript with strict mode, || and ?? behave identically.

After const { foo: bar } = obj, what’s true?

foo is now a local binding holding obj.bar.
bar is now a local binding holding obj.foo. foo is not in scope.
Both foo and bar are in scope, both holding obj.foo.

What does the last line log?

let taxPercent = 20;
const makeTotal = () => {
let calls = 0;
return (cents: number) => {
calls++;
return { total: cents + (cents * taxPercent) / 100, calls };
};
};
const total = makeTotal();
total(10_000);
taxPercent = 10;
console.log(total(10_000));
{ total: 12000, calls: 2 }
{ total: 11000, calls: 2 }
{ total: 11000, calls: 1 }

Quiz complete

Score by topic