TypeScript Optional and Default Parameters Quiz
A 30-question TypeScript quiz exploring optional parameters, default parameter values, undefined handling, rest parameters, function declaration rules, and parameter type inference.
Question 1
What does a question mark after a parameter name represent?
Question 2
What type does an optional parameter implicitly include?
Question 3
What is the type of msg?
function log(msg?: string) {
return msg;
}Question 4
Optional parameters must appear:
Question 5
A default parameter value applies when:
Question 6
What value does count receive?
function increment(count: number = 10) {
return count;
}
increment();Question 7
What does a default parameter imply about requiredness?
Question 8
What is the type of n?
function use(n = 5) {
return n;
}Question 9
A parameter cannot be both:
Question 10
Defaults are evaluated:
Question 11
What does this return?
function f(v: number = 3) {
return f(undefined);
}
Question 12
Optional parameters implicitly behave like:
Question 13
Why must optional parameters come last?
Question 14
Why is this invalid?
function bad(a?: number, b: string) {}Question 15
Overloads often avoid optional parameters when:
Question 16
Rest parameters behave like:
Question 17
What does this call output?
function join(sep = ',', ...items: string[]) {
return items.join(sep);
}
join('-', 'a', 'b');Question 18
Rest parameters cannot be:
Question 19
Why does this compile?
function show(x?: number) {}
show(undefined);Question 20
Optional does NOT imply:
Question 21
What value is assigned to rate?
function calc(total: number, rate = total * 0.1) {
return rate;
}
calc(50);Question 22
What is true about default parameters?
Question 23
When is an optional parameter preferred over a default?
Question 24
Which call distinguishes actual undefined from omission?
function check(v?: number) {
return arguments.length;
}Question 25
Default parameters are useful when:
Question 26
A parameter with a default is considered:
Question 27
Optional parameters should be avoided when:
Question 28
Which is true about function calls involving default parameters?
Question 29
Optional parameters are commonly used for:
Question 30
Overall, default parameters help developers by:
