0 day streak
javascript / beginner
Snippet

Defining Functions with Parameters and Return Values

Functions are reusable blocks of code. Parameters (a, b) act as placeholders for input values, and the 'return' keyword sends a value back to where the function was called.

snippet.js
javascript
1
2
3
4
5
6
function multiply(a, b) {
return a * b;
}
const result = multiply(5, 3);
console.log(result);
nodejs
Breakdown
1
function multiply(a, b)
Declares a function named 'multiply' that takes two inputs.
2
return a * b;
Calculates the product and returns it.
3
const result = multiply(5, 3);
Calls the function with 5 and 3, storing the returned value (15) in 'result'.