0

I know that:

console.log({}.length);
> undefined

console.log([].length);
> 0

console.log([] + {});
> [object Object]

but,why ([] + {}) is [object Object]

console.log(([] + {}).length);
> 15

Why...I can't figure out

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
张小咩
  • 9
  • 7

1 Answers1

1

My console gives me this:

typeof []
"object"
typeof {}
"object"
typeof [] + {}
"object[object Object]"
typeof ([] + {})
"string"

The length of your last console.log is because it is a string.

Danmoreng
  • 2,367
  • 1
  • 19
  • 32