在console.log中具有控制台日志输出的函数打印未定义 [英] A function with a console log output inside console.log prints undefined

查看:115
本文介绍了在console.log中具有控制台日志输出的函数打印未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function haha(){
  console.log('haha');
}

console.log(haha());

打印:

haha
undefined

是否因为你没有指定退货在函数中它将返回undefined,这是第二个console.log正在输出的内容?

Is it because if you don't specify return in a function it will return undefined and this is what the second console.log is outputting?

推荐答案

它返回 undefined 因为基本上你的函数没有返回任何东西。

It returns undefined because basically your function doesn't return anything.

你可以例如返回haha字符串或任何你喜欢的内容。

You could e.g. return a "haha" string or whatever you like.

function haha(){
  console.log('haha');
  return 'haha';
}

console.log(haha());

这篇关于在console.log中具有控制台日志输出的函数打印未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆