簡體   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