JAVASCRIPT Tutorial
A return value is the data that a function sends back to the code that called it.
To return a value from a function, use the return
keyword followed by the value.
function sum(a, b) {
return a + b;
}
The return value can be any data type, including primitives (e.g., numbers, strings) or complex objects (e.g., arrays, objects).
if a function doesn't explicitly return a value, it returns undefined
.
function double(x) {
return x * 2;
}
const result = double(5); // result = 10
return
keyword: Used to send data back to the calling code.