O'Reilly logo
  • Bob Massarczyk thinks this is interesting:

In JavaScript, function arguments are references to the actual data. Setting the color’s rating like this is bad because it changes or mutates the original color object. (Imagine if you tasked a business with redacting and sharing your birth certificate and they returned your original birth certificate with black marker covering the important details. You’d hope that a business would have the common sense to make a copy of your birth certificate and return the original unharmed.) We can rewrite the rateColor function so that it does not harm the original goods (the color object):


Cover of Learning React


No, only if those arguments are non-primitive data types like objects and arrays. Primitive data types like strings, numbers and boolean are copy by value, not reference.