Recall & Review
beginner
What does 'Parameters type' mean in TypeScript?
It means specifying the type of values that a function expects as inputs, so the function knows what kind of data it will receive.
Click to reveal answer
beginner
How do you write a function in TypeScript that takes a number as a parameter?
You write the parameter name followed by a colon and the type. Example: <pre>function double(x: number) { return x * 2; }</pre>Click to reveal answer
beginner
What happens if you pass a wrong type to a function with typed parameters in TypeScript?
TypeScript will show an error before running the code, helping you fix the mistake early.
Click to reveal answer
intermediate
Can function parameters in TypeScript have optional types?
Yes, you can mark parameters as optional with a question mark. Example: <pre>function greet(name?: string) { ... }</pre>Click to reveal answer
beginner
What is the benefit of using parameter types in functions?
It helps catch mistakes early, makes code easier to understand, and improves code quality by ensuring correct data is used.
Click to reveal answer
How do you specify a string parameter named 'text' in a TypeScript function?
✗ Incorrect
In TypeScript, you write the parameter name followed by a colon and the type.
What does the question mark (?) mean in a parameter like 'name?: string'?
✗ Incorrect
The question mark marks the parameter as optional, so it can be omitted.
What will TypeScript do if you pass a number to a function expecting a string parameter?
✗ Incorrect
TypeScript checks types before running and shows errors if types don't match.
Which of these is a correct way to define a function with two parameters: a number and a boolean?
✗ Incorrect
You specify each parameter name followed by its type separated by commas.
Why is it helpful to use parameter types in functions?
✗ Incorrect
Parameter types help catch mistakes early and improve code clarity.
Explain how to define a function with typed parameters in TypeScript and why it is useful.
Think about how you tell the function what kind of data it should expect.
You got /2 concepts.
Describe what happens if you pass the wrong type of argument to a function with typed parameters in TypeScript.
Consider how TypeScript helps you avoid bugs.
You got /2 concepts.