Describing Parameters & Return Values
Vocabulary for describing function inputs, outputs, types, and side effects
Key vocabulary
- Parameters: "accepts / takes" + required/optional + type + name
- Returns: "returns a [type]" / "resolves with" (async) / "rejects with" (async error)
- Exceptions: "throws a [ExceptionType] if [condition]"
- Arrays: "an array of strings" — not "some strings" or "multiple strings"
- Side effects: "mutates" (changes in place) vs "returns a new" (no mutation)
Question 0 of 5
A function signature is: function createUser(name: string, age: number, isAdmin?: boolean): User
Which description of its parameters is most accurate?
"Accepts a required string name, a required number age, and an optional boolean isAdmin parameter" is correct. Parameter description vocabulary:
- "accepts / takes" — introduces parameters
- "required" — must be provided
- "optional" — has a default or can be omitted (marked with
?in TypeScript) - State the type — "a string," "a number," "a boolean" — not just the name
- "parameter" is the formal term; "argument" refers to the value passed at call time
Which sentence best describes a function that returns a Promise? async function loadConfig(): Promise<Config>
"Resolves with a Config object when the asynchronous operation completes" is correct for Promise-returning functions. Async return vocabulary:
- "resolves with" — when the Promise succeeds
- "rejects with" — when the Promise fails (e.g., throws)
- "returns a Promise that resolves with" — more explicit form
A function has this JSDoc: @param {string[]} ids - Array of user IDs to fetch. Which spoken description is correct?
"Accepts an array of strings representing user IDs" is correct. When describing array parameters:
- "an array of [type]" — not "some [type]s" or "multiple [type]s"
- "representing" — explains what the values mean, not just their type
- In TypeScript:
string[]orArray<string>both mean "an array of strings"
How do you describe a function that can throw an error? Which sentence is correct?
"Throws an InvalidInputError if the email format is invalid" is correct. Exception description vocabulary:
- "throws" — the standard verb for raising exceptions
- Name the exception type — "InvalidInputError," "TypeError," "NotFoundException"
- "if [condition]" — specify when the exception occurs
@throws {InvalidInputError} If the email format is invalid. In Javadoc: @throws IllegalArgumentException If the parameter is null. In Python docstrings: Raises: ValueError: If the input is empty.What does it mean when a function description says it has a side effect of "mutating the original array"?
"Modifies the array passed as an argument directly, rather than returning a new one" is what "mutates the original array" means. Side effect vocabulary:
- "mutates" — directly modifies an existing object in place
- "in place" — without creating a new copy
- Contrast: "returns a new array" — pure function, no mutation
Array.prototype.sort() mutates the original; Array.prototype.map() returns a new array. Knowing this distinction prevents bugs. In code reviews: "This mutates the input — should it return a new array instead?" is a common and important comment.