javascript中的console.log和return有什么区别
问题描述:
JavaScript 中的 console.log 和 return 有什么区别?他们都看到在终端打印出来的东西.
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.
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
控制台.log
Console 对象提供对浏览器调试控制台的访问(例如,Firefox 中的 Web 控制台)
The Console object provides access to the browser's debugging console (e.g., the Web Console in Firefox)
console.log
在开发工具 concel 选项卡下向 Web 控制台输出消息.
console.log
Outputs a message to the Web Console under development tool concel tab.