A function with a console log output inside console.log prints undefined

為{幸葍}努か 提交于 2019-12-02 12:13:58

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

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

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

console.log(haha());

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?

Yes, console.log() prints the arguments passed to it. Arguments passed to it in the second time is the returned value of haha() which is undefined

First console log is the due to the console.log inside haha.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!