Why is my JavaScript function returning undefined instead of value?

16 hours ago 3
ARTICLE AD BOX

I am new to JavaScript and trying to understand how functions return values. I created a simple function to add two numbers and store the result in a variable.

However, when I call the function and log the result in the console, it prints undefined instead of the expected value. There are no syntax errors in the browser console.

Here is my complete code:

function addNumbers(a, b) { let sum = a + b; } let result = addNumbers(5, 3); console.log(result);

My expectation was that the output should be 8, but it shows undefined.

I think I might be missing something related to returning values from functions, but I am not sure what exactly is wrong. Can someone explain why this is happening and how to fix it?

Read Entire Article