为什么控制台内的console.log(“ hello”)返回未定义? [英] Why does console.log("hello") inside console return undefined?

查看:325
本文介绍了为什么控制台内的console.log(“ hello”)返回未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于好奇,为什么在控制台内写入 console.log( hello)会返回未定义状态?

Out of curiosity, why does writing console.log("hello") inside console return undefined?

出于相同的原因在C中定义void函数吗?

Is it for the same reasons in defining void function in C?

推荐答案

console.log只需编写文本并以未定义返回即可。
如果创建一个函数,则添加一个返回值,不会有未定义的值,它将返回添加的值。
示例:

The console.log just write a text and return with undefined. If you create a function, add a returning value, there will be not undefined, it will returns with the added value. Example:

function writer(){
    console.log("write new line");
    return "ok";
}

如果您调用writer(),则新的输出是 ok 写新行之后的一行。

If you call the writer() that the output is "ok" in new line after "write new line".

这篇关于为什么控制台内的console.log(“ hello”)返回未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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