Function Declarations and Parameters
A function is a reusable set of instructions. Parameters receive the values supplied as arguments, and return supplies a result to the caller.
Define the job once, then call it with different article data.
See the mechanism
800↓800Follow one example
The declaration defines instructions; it does not run the calculation. The first call supplies 800 as words and receives 4. The second call supplies 1200 and receives 6 in a separate invocation. return ends that invocation. Printing and returning are different: the outer console.log prints the returned value.
Predict, change and check
Predict: If you remove return but keep words / 200 inside the function, what will the caller receive?
Test your explanation: Remove return, run the calls, and observe undefined. Restore it. Then call the same function with 0 words to check a meaningful boundary.
The tasks below ask you to explain that result and apply the idea to different inputs.
Apply and distinguish
Calling and defining are different events
A function definition creates callable behavior; a call supplies actual arguments and executes it. Parameters are local bindings for that invocation. Returning a value is different from logging one, and reaching the end of an ordinary function without returning supplies undefined.
JavaScript passes argument values. When a value is an object reference, the callee can mutate the referenced object, but reassigning the parameter does not reassign the caller's variable. Test both a returned result and the original object when the function promises not to mutate its inputs.
Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.