Difference between console.log and return in javascript? [closed]

What are the instances when you would use console.log and return in javascript?

I've just started learning javascript and I want to know what are some instances when I'd use them?


Solution 1:

From http://blogs.msdn.com/b/cdndevs/archive/2011/05/26/console-log-say-goodbye-to-javascript-alerts-for-debugging.aspx

console.log will display the parameter passed to the log method in the console window. Use this method to display a string or variable in the console window.

You can use the console class in your code as well, much like we can use JavaScript alerts.

<script type = "text/javascript"> 
    function tryConsole() { 
        console.log("hello world"); 
    } 
</script>

When using the return statement, the function will stop executing, and return the specified value.

Solution 2:

Actually there's nothing in common between them.

return - returns execution to the caller with optional result

console.log() - logs out information in console.