Difference between 'console.log' and 'return'


#1

well, i finished lesson about functions and was a task to use 'return' to show what i did on a screen, but early i used 'console.log' to show what i coded... well, what the difference if 'return' and 'console.log' do the same?
thanks for help :slightly_smiling:


#2

console.log prints to the screen whereas return is a keyword that manages the return to the calling scope including the transport of value from the function scope to the calling scope. Back there it could be used by console.log or the default echo of the last value to be shown on the screen but it could as well be used anywhere else as a value. For example

Math.random() returns a random number but it's purpose is not solely to display that number but more likely to use this value in your program.


#3

Just a note on that console.log() does not print things to the screen if you were making a website it prints things to the console if I am right document.write() prints things to the screen.


#4

Yes but it's probably better to manipulate a div than using document.write().