Why comma ' , ' and plus ' + ' log the console output in different pattern?

前端 未结 2 424
温柔的废话
温柔的废话 2020-12-09 04:01

I am using the console.log statement for debugging , but came across a scenario where using \',\' or \'+\' with console.log statement is logging the output in different pat

2条回答
  •  一个人的身影
    2020-12-09 04:37

    +(string concatenation operator) with object will call the toString method on the object and a string will be returned. So, '' + object is equivalent to object.toString(). And toString on object returns "[object Object]".

    With , the object is passed as separate argument to the log method.

提交回复
热议问题