DEV Community

Discussion on: JavaScript Interview Questions

Collapse
 
prajesh_kun profile image
Prajesh Gawhale

Hi Jon!

Thank you for sharing your thoughts! I just wanted to clarify a small point about JavaScript. While it's a common misconception, JavaScript technically doesn't use pass-by-reference. Instead, it uses pass-by-value for everything, but with objects (including arrays and functions), the "value" that's passed is actually a reference to the memory location. This is why it sometimes behaves like pass-by-reference.

To break it down:
Pass-by-Value (Primitives): A copy of the value is passed, so changes inside the function don’t affect the original variable (e.g., numbers, strings, booleans).

Objects (Reference-like behavior): A copy of the reference is passed, which allows changes to the object's properties to reflect outside the function. However, if you reassign the parameter inside the function, the original reference remains unchanged.

It’s a subtle distinction, but it’s a good one to keep in mind! Hope this helps! 😊