繁体   English   中英

在javascript中使用console.log时摆脱新行

[英]Getting rid of a new line when using console.log in javascript

我正在尝试在学习环境中运行此函数,但它会导致“您的程序的输出比预期长”的错误,因为 console.log 默认生成换行符。 有什么办法可以解决这个问题吗?

function calcSquare() {
    x = document.getElementsByTagName('input')[0].value;
    result = x**2
    console.log("The square of", parseInt(x), "is", parseInt(result))
}

如果您在节点中,则可以使用process.stdout.write("foo"); . 您可以多次调用它而无需换行。

process.stdout.write('foo');
process.stdout.write('bar');

输出: foobar

暂无
暂无

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

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