Can some one please let me know why an addition of an empty object and an array is a string
in javascript
[ ] + [ ] = string
[ ] + { } = string
{ } + [ ] = [object Object]
{ } + { } = [object Object][object Object]
Can some one please let me know why an addition of an empty object and an array is a string
in javascript
[ ] + [ ] = string
[ ] + { } = string
{ } + [ ] = [object Object]
{ } + { } = [object Object][object Object]
This is because +
operator tries to convert to number or string, which ever is common type.
[].toString()
will return ""
, but {}.toString()
will return [object Object]
console.log([].toString())
console.log({}.toString())