Read the rule
A support team needs request titles that tell staff what to look for. Accept a title only if it is text and has at least 10 characters after removing spaces at the beginning and end. Spaces inside the title still count.
Before writing code, decide what should happen at the boundary. "Printer 01" contains exactly 10 characters and should pass. " Slow PC " contains 11 characters as typed, but only seven after trimming, so it should fail. A missing value should also fail.
Write down the expected result
A test needs two things: the input and the result the rule requires. If you simply record what the current code does, a defective function can pass its own tests. Write your expected outcomes from the rule first, then compare them with the code.
function acceptsTitle(title) {
return typeof title === 'string' && title.trim().length >= 10;
}
The type check runs first. If the input is not a string, JavaScript stops evaluating the right-hand side, so a missing value is rejected without trying to call trim().