Basic JavaScript - Return a Value from a Function with Return

Tell us what’s happening:
My question is regarding the modules Passing Values to Functions with Arguments and Return a Value from a Function with Return.

As I understand it, we’re doing almost a similar thing in both modules which is computing numbers. Then why do we need to write console.logs() in when using Arguments but not when using the Return function? Why are their formats so different?

Just trying to understand if my logic is a bit incorrect. Thank you for helping :slight_smile:

Your code so far

function functionWithArgs(arg1,arg2){
  console.log(arg1+arg2);
}
functionWithArgs(8,2);  //Outputs 10
functionWithArgs(12,3);  //Outputs 15
function timesFive(num){
  return num*5;
}
const answer=timesFive(10);  // Outputs 50

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Return a Value from a Function with Return

Link to the challenge:

console.log does not actually return a value, it just prints information to the console, which is commonly used for debugging purposes. If you want to return a value from a function then you need to use the return statement. Or in those cases when you don’t mind returning undefined then you don’t need an explicit return statement.

So the functionWithArgs function above prints the answer to the console but the function itself returns undefined because there is no return statement.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.