0
confused
please ?when we use console.log and when we use return?
5 ответов
+ 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...
+ 1
Return is used at the end of a function.
+ 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.
0
I still don't get this
0
Ask a question blizzard