Backbencher.dev

JS Daily 12 - Default Return Value of a Function

Last updated on 2 Dec, 2020

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().

--- ○ ---
Joby Joseph
Web Architect