console.log()中+和之间有什么区别?

时间:2020-05-18 16:15:18

标签: reactjs redux react-redux

console.log('The initial state: ', store.getState());

此行给出正确的输出。

console.log('The initial state: '+ store.getState());

此行给出了一个奇怪的输出:初始状态Object Object。 有什么区别?

为什么还要给出2个对象而不是1个?

1 个答案:

答案 0 :(得分:1)

通过使用,您告诉console.log它应该带有多个参数。

另一方面,+告诉JavaScript它需要将两个参数组合为一个参数。由于字符串不能与对象配合在一起,您将获得所看到的。 Console.log在将对象显示为对象而不是尝试将其转换为字符串方面做得更好。

相关问题