Skip to the workspace
Pebellslearn by building
Functions  ›  Lesson

Function Declarations and Parameters

Functions 12 min

javascript / Function Declarations and Parameters

Explore each scene at your own pace.

01 · Function Declarations and Parameters

Function Declarations and Parameters

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

Walk through the modelFunction Declarations and ParametersAuthored snapshots of the example; use Run below to test the code.
argument800
parameter words800
A call supplies a value to a named parameter.
1 of 3

Follow one example

javascript

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.

Scene 1 of 2
Project context and further resources
Additional resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.