Can someone please explain for me how return works


I just wish to understand the word return and what it's work if you can use the console.log to call up the function or just the function name


console.log is used mostly for debugging purposes as well as printing information to the screen. Not the same as returning a value.

Return is used for functions where it returns the value of whatever you've had it return but does not actually print it. Not everything needs to be console.log printed or anything. Certain things you don't want printed.

So using the return statement keeps that inside the function. now if you did

console.log("This is a " + randomFunction());

this would print out what was returned into the console. But again, if you've made a function that's not meant to print things out but rather do some kind of calculation or something you'd be lost without the return statement.


Can you please explain with more details how it works and when it works using codes if you can. Really appreciate your help. Thanks.


Return is pretty straight forward. Usually you only use it in functions, usually at the end. Though if you have a function with lots of if/else statements return after each one in place of where you would usually do console.log(); is what you want to do.

A lot of the time console.log doesn't need to be used as a lot of the things you are doing don't require nor should they be printed nor would you want them to be printed. There isn't a whole lot more on the topic that I know about, unfortunately.

console.log = actually printing something for user to see OR debugging purposes
return = used in functions so that not every calculation (the user doesn't need to see the result of everything) is seen in the console or display, yet still completes what console.log does, except it doesn't show it.


Thanks once again. I now understand to an extent how it works. once again I really appreciate.


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