JavaScript basics: Named functions
A named function groups a reusable operation; calling it runs its body.
Current edit
Understand the pattern
A named function groups a reusable operation; calling it runs its body.
A named function groups a reusable operation; calling it runs its body.
Misconceptions to reject
- A string containing code executes automatically when it is assigned.
- A successful element lookup guarantees that the rest of an event handler is correct.
This is a code-inspection lab, not a full JavaScript runtime.
Worked example and expected result
function welcome() { return "Welcome to the lab"; }
const greeting = welcome();
const heading = greeting + ".";A named function groups a reusable operation; calling it runs its body.
Explain it
Apply it elsewhere
Keep the momentum.
Complete the lab, then explain and apply the pattern.
Next: JavaScript basics: Function parametersTry an incident drillAnonymous lesson and mastery progress lasts for this session. Sign in to keep synced lesson XP between sessions; mastery stays device-local. No speed bonus, lost lives, or hint penalties.
Keep learning
- 01JavaScript basics: Array lengthlength counts the array slots; the last valid index is normally length minus one.Practice
- 02JavaScript basics: Function parametersParameters let the same function work with different inputs without duplicating its body.Practice
- 03JavaScript basics: Return valuesreturn supplies a result to the caller. A function without an executed return yields undefined.Practice