What is the output of following code?
function sum(a, b) {
const result = a + b;
}
console.log(sum(2, 4));
----o----
Output is undefined
.
If a function does not return a value explicitly, undefined
is returned. Here, even though we found the sum, we did not return the result
. Therefore, the default undefined
is returned by sum()
.