Why does {. . . .0} evaluate to {}?

Mist picture Mist · Dec 25, 2018 · Viewed 9.2k times · Source

I just found {....0} in friend's code. Evaluating it in console returns {} (empty object).

Why is that? What is the meaning of 4 dots in JavaScript?

Answer

NikxDa picture NikxDa · Dec 25, 2018

Four dots actually have no meaning. ... is the spread operator, and .0 is short for 0.0.

Spreading 0 (or any number) into an object yields an empty object, therefore {}.