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.

A Server Action file does const user = await getCurrentUser() at module scope and then references user inside the exported action body. What goes wrong?

getCurrentUser() runs once at module load, and every later request closes over that same user binding — authorization checks pass or fail based on whoever first loaded the module, not the current caller.
Nothing — module-scope captures are re-evaluated per request, so each invocation reads a fresh user.
The build fails because Server Actions cannot reference module-scope bindings at all.

Quiz complete

Score by topic