Web development
Functions and Reuse
Updated Oct 28, 2026
A function groups instructions under a name. Parameters receive input, and return sends a result back to the caller. Calling a function does not automatically display the return value; use it or log i
What you’ll learn
Understand and practise functions and reuse.
Explanation
A function groups instructions under a name. Parameters receive input, and return sends a result back to the caller. Calling a function does not automatically display the return value; use it or log it. Choose descriptive names and test with different inputs.
Function ប្រមូលសេចក្ដីណែនាំក្រោមឈ្មោះមួយ។ Parameter ទទួលទិន្នន័យ ហើយ return ផ្ញើលទ្ធផលត្រឡប់ទៅអ្នកហៅ។
Example
function add(a, b) { return a + b; } console.log(add(2, 3));
Practice
What does add(2, 3) return?
Answer and explanation
Show answer / បង្ហាញចម្លើយ
5. The parameters a and b receive 2 and 3.
Quick recap
A function groups instructions under a name.