DEV Community

Discussion on: 📖 History of "Stop unnecessary re-rendering component in React !!"

Collapse
 
jorge_rockr profile image
Jorge Ramón

Everything in JavaScript is pass-by-reference so if your function modifies an object or array then the change applies to the original object.

The case of the "pass-by-value" in primitive date types it's because primitive data types are immutable so yeah, you are still passing the reference to a function but it doesn't matter cause its immutability

Collapse
 
thuutri2710 profile image
Tris
Thread Thread
 
jorge_rockr profile image
Jorge Ramón

Thanks, exactly what I said but remember primitives are immutable so that why they act as "pass-by-value"

Thread Thread
 
thuutri2710 profile image
Tris

Oh, let me confirm again. In JS, we only "pass-by-value"

Thread Thread
 
jorge_rockr profile image
Jorge Ramón

Okay, I got your point.

Technically, JS works "pass-by-value" since you pass a copy of a reference. But if you modify that copy of the reference then it modifies the original object so that's basically "pass-by-reference" xd

Same as Primitive Data Types Immutability is basically the same as pass-by-value.

So it depends, you can see the glass half empty or half full

Thread Thread
 
thuutri2710 profile image
Tris

Agree with you