Javascript console.log(object) vs. concatenating string

后端 未结 5 650
孤城傲影
孤城傲影 2020-12-03 02:26

I\'m running this in node.js:

> x = { \'foo\' : \'bar\' }
{ foo: \'bar\' }
> console.log(x)
{ foo: \'bar\' }
undefined
> console.log(\"hmm: \" + x)
         


        
5条回答
  •  天涯浪人
    2020-12-03 03:07

    Use JSON.stringify when printing an object with string appending

    console.log("Haa"+JSON.stringify(x))
    

提交回复
热议问题