TypeScript Functions and Parameters Quiz
A 30-question TypeScript quiz covering function declarations, expressions, parameter types, optional and default parameters, rest arguments, and return type handling.
Question 1
Which syntax defines a function declaration?
Question 2
Which statement is true about function expressions?
Question 3
What is the type of fn?
const fn = (x: number): number => x * 2;Question 4
Why is it helpful to annotate a function's return type?
Question 5
Which is a valid function type annotation?
Question 6
What does this parameter list mean?
function greet(name: string, age?: number) {}Question 7
Which is true about optional parameters?
Question 8
What type does TypeScript infer for the return value?
function add(a: number, b: number) { return a + b; }Question 9
Which statement about parameter types is correct?
Question 10
What does the parameter type indicate?
function log(value: string | number) {}Question 11
What is true about default parameters?
Question 12
What value does this function return?
function multiply(a: number, b: number = 2) {
return a * b;
}
multiply(5);Question 13
Which syntax defines a rest parameter?
Question 14
What does total receive?
function sum(...nums: number[]) {
return nums.length;
}
sum(1, 2, 3);Question 15
Which rule applies to rest parameters?
Question 16
What is the inferred return type?
function hello() {
return 'hi';
}Question 17
When is it useful to annotate return types?
Question 18
Which return type indicates a function never finishes?
Question 19
What is the return type?
function fail(msg: string): never {
throw new Error(msg);
}Question 20
What does void represent as a return type?
Question 21
What is the type of this function?
const fn = function(a: number, b: number): number {
return a + b;
};Question 22
What does a function overload define?
Question 23
Which statement about arrow functions is correct?
Question 24
What rule applies to optional parameters?
Question 25
Which pattern ensures a function always returns a string?
Question 26
Which keyword is used for asynchronous functions?
Question 27
What is the return type of an async function?
Question 28
Rest parameters are useful because they:
Question 29
Which type best represents a function with no parameters and no return value?
Question 30
Why is typing parameters important?
