0

confused

please ?when we use console.log and when we use return?

21st Aug 2016, 11:21 PM
Scorpion Fox
Scorpion Fox - avatar
5 Respuestas
+ 4
console.log is used to output to the console... Return will pass the return value back to the caller function getstuff(){ return "stufff"; } If you call getstuff(); There will be no output to the console.. If you call console.log(getstuff()); Then the console will output what is returned by getstuff() or "stuff" If you want the function to do it you could rewrite the function to something like.. function getstuff(){ var stuff = "stuff"; console.log(stuff); return stuff; } Then when you call getstuff(); The console will output stuff and your return value will be stuff.. Or you could.. var s = getstuff(); console.log(s); A function must always have a return in js. In more advanced languages functions can be a void function and not have a return.. But in js you can just write return; for a void function that has no return value...
22nd Aug 2016, 8:55 PM
fjlj
+ 1
Return is used at the end of a function.
22nd Aug 2016, 5:36 AM
Oscar
Oscar - avatar
+ 1
-console.log() we used in V8 in chrome. -print() we used in spidermonkey. -return we used for returning values by call functions or classes.
18th Oct 2016, 2:41 PM
pringlz
0
I still don't get this
22nd Aug 2016, 4:27 AM
Blizzard-Spin
Blizzard-Spin - avatar
0
Ask a question blizzard
24th Aug 2016, 12:29 PM
John Gachina
John Gachina - avatar