Skip to main content
JAVASCRIPT-BASICS5 MIN READ

Give every function one clear job

Write a JavaScript function with clear inputs, one primary output, and visible side effects.

The move: design the function contract before the body. A function contract is small: inputs, output, side effects. In JavaScript, this contract often lives in the name and the first few lines rather than a formal type system. That means beginners need to be deliberate. Inputs Parameters should be the minimum data the function needs. price is clearer than item if only the price is used. items is clearer than data when the function expects an array. Output Return the thing the caller needs next. If a function sometimes returns a number and sometimes returns false, the caller now has…

Read the full lesson

Sign up free — one personalized lesson every day, matched to your role and goals.

Already have an account? Sign in

← Back to library
Contact us