简体   繁体   English

javascript中的console.log和return有什么区别

[英]whats the difference between console.log and return in javascript

Whats the difference between console.log and return in JavaScript? JavaScript 中的 console.log 和 return 有什么区别? 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. return 语句结束函数执行并指定要返回给函数调用者的值。

Console.log控制台日志

The Console object provides access to the browser's debugging console (eg, the Web Console in Firefox) Console 对象提供对浏览器调试控制台的访问(例如,Firefox 中的 Web 控制台)

console.log Outputs a message to the Web Console under development tool concel tab. console.log将消息输出到开发工具 concel 选项卡下的 Web 控制台。

console.log() is meant to print output to the console. console.log()用于将输出打印到控制台。 However, return is meant to send data back to variable when a function is called, like this:但是, return是在调用函数时将数据发送回变量,如下所示:

var foo = bar();

If bar() had a return statement, the value would be passed to foo .如果bar()return语句,则该值将传递给foo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM