JavaScript basics: Return values
return supplies a result to the caller. A function without an executed return yields undefined.
Current edit
Understand the pattern
return supplies a result to the caller. A function without an executed return yields undefined.
return supplies a result to the caller. A function without an executed return yields undefined.
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 total(a, b) { return a + b; }
const points = total(100, 25);
const doubled = total(points, points);return supplies a result to the caller. A function without an executed return yields undefined.
Explain it
Apply it elsewhere
Keep the momentum.
Complete the lab, then explain and apply the pattern.
Next: JavaScript basics: Template stringsTry 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.