Whats the difference between console.log and return in JavaScript? they both seen to print out things in terminal.
isPrime(num){
if (num % i === 0)) {
return false ;
}
for (var i = 2; i < num; i++) {
if (num % i === 0) {
return false;
}
}
Return
The return statement ends function execution and specifies a value to be returned to the function caller.
Console.log
The Console object provides access to the browser's debugging console (eg, the Web Console in Firefox)
console.log
Outputs a message to the Web Console under development tool concel tab.
console.log()
is meant to print output to the console. However, return
is meant to send data back to variable when a function is called, like this:
var foo = bar();
If bar()
had a return
statement, the value would be passed to foo
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.