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?
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 {}
.
Three dots in an object literal are a spread property, e.g.:
const a = { b: 1, c: 1 }; const d = { ...a, e: 1 }; // { b: 1, c: 1, e: 1 }
The last dot with a 0 is a number literal .0
is the same as 0.0
. Therefore this:
{ ...(0.0) }
spreads all properties of the number object into the object, however as numbers don't have any (own) properties you get back an empty object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With