Parameters make behavior reusable
A parameter names an input the caller provides. Returning a value lets the caller decide what to do with the result instead of forcing every function to change the page directly.
Scope limits where names exist
Variables declared inside a function or block are normally available only there. Smaller scopes reduce accidental interference and make it easier to see which code can change a value.
A familiar example
Formatting a result count
- A function receives the numeric count.
- It chooses singular or plural wording.
- It returns the finished sentence for the page to display.
What to remember
- Functions name and isolate behavior.
- Parameters are inputs; return values are outputs.
- Keep values in the smallest useful scope.