Type System Basics — Series 3

Preview — 3 of 10 questions

Which declaration correctly annotates both parameters and the return type?

javascript
function add(a: number, b: number): number {
  return a + b;
}
Afunction add(a, b): number, number { return a + b; }
Bfunction add(a: number, b: number): number { return a + b; }
Cfunction add(a, b) : (number, number) => number { return a + b; }
Dfunction add<number>(a, b) { return a + b; }

What are the inferred types of a and b?

javascript
const a = "hello";
let b = "hello";
ABoth are string
BBoth are "hello"
Ca is string, b is "hello"
Da is "hello", b is string

What is the inferred type of mixed?

javascript
const mixed = [1, "two", 3];
A(string | number)[]
Bany[]
C[number, string, number]
Dnumber[], with "two" reported as an error

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.