Describing Function Purpose
Action verbs, sentence patterns, and vocabulary for explaining what a function does
Core sentence pattern
- "This function [verb] [object] and returns [result]."
- Validation: "checks whether / validates that"
- Retrieval: "fetches / retrieves / gets"
- Transformation: "transforms / converts / parses / serializes"
- Side effects: "logs / emits / mutates / triggers / writes to"
- Always mention the edge case: "or returns undefined/null/false if not found"
Question 0 of 5
You are reviewing this function:function validateEmail(input) { return /^[^@]+@[^@]+.[^@]+$/.test(input); }
Which description is most accurate?
"Checks whether the input string matches a basic email format and returns true or false" is correct. Key vocabulary for describing functions:
- "checks whether" — for validation/boolean functions
- "returns true or false" — clearly names the return type
- "matches a format" — describes what the regex test does
Choose the best description for: function getUserById(id) { return db.users.find(u => u.id === id); }
"Takes an ID and returns the user object that matches it, or undefined if not found" is correct. The description covers:
- Input — "takes an ID"
- Output — "returns the user object"
- Edge case — "or undefined if not found" (what
.find()returns when no match exists)
Which action verb best fills the blank? "This function ___ the raw API response into a structured User object."
"Transforms" is correct. Standard action verbs for function descriptions:
- calculate — computes a numeric result
- validate — checks correctness
- transform / convert — changes one form to another
- fetch / retrieve — gets data from a source
- parse — extracts structured data from raw input
- serialize / format — converts to a specific output format
- filter — selects a subset
You see: async function fetchUserData(userId) { const res = await api.get("/users/" + userId); return res.data; }
What language should you use to describe this function in a code review?
"Asynchronously fetches user data from the API by user ID and returns the response data" is the correct register for a code review. It uses:
- "asynchronously" — signals the async/await nature
- "fetches" — precise verb for HTTP GET operations
- "by user ID" — explains how the target is identified
- "returns the response data" — names the return value (not the full response, just
.data)
Match the verb to the function type. Which sentence correctly describes a function with a side effect?
"Logs the error to the console and emits a monitoring event" correctly describes a function with side effects. Side effect vocabulary:
- "logs" — writes to console/file
- "emits" — fires an event
- "mutates" — changes an existing object
- "triggers" — starts another process
- "writes to / updates" — modifies storage