1. 1

  2. 2

    The triple dot immediately followed by the conditional is visually ambiguous. Would be more clear to add parentheses.

    1. 1

      I wish the article would have explained what the triple dot operator even does (as well as its precedence level) so I could verify for myself that the proposed solution works. Don’t just hand me your code — teach me something.

      1. 2

        the triple dot operator is not a “normal” operator…it does not have a precedence. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Operator_precedence

        An operator takes a value and produce another value…like +“5” that takes “5” and produce 5. Binary operators take two values, the ternary takes three values but the result does not change: a single value is produced.

        On the contrary you cannot simply do: …expression; nor …value; The array spread operators does expand an array, it does not produce a value…the expression is evaluated and then the resulting values is expanded. Many values are produced. The object spread operator does shallow clone an object, it does not produce a value as well. As I described in the article, the expression will be evaluated and THEN the object spread will perform its copy job. The rest operator takes one or more values and THEN it will insert them into an object/array. Again, there is no resulting value.

        We call the rest/spread … operators because, in fact, them perform an operation. But they are quite different from operators in general…they do not interfer.

      2. 1

        AirBnB style guide imposes them, so If you prefer put them on :)