leonardomso / 33-js-concepts

📜 33 JavaScript concepts every developer should know.
MIT License
62.64k stars 8.74k forks source link

Question 3 "Value Types and Reference Types" is wrong, meaningless, and misleading #481

Open finalchild opened 5 months ago

finalchild commented 5 months ago

There is no such thing called "value type" or "reference type" in JavaScript. The distinction doesn't exist, not in the spec nor in the implementation. The distinction is a common myth, but factually wrong. JavaScript is not Java.

One does not simply pass strings by value. Strings are not a "non-reference type". Strings are "primitive" in the sense that they don't constitute of properties. This has nothing to do with value and reference.

TL;DR: Almost all types of values in JavaScript are stored as references, and passed by sharing. The small set of exceptions are implementation-specific.

For reference, a nice answer written by jmrk: https://stackoverflow.com/questions/74004695/how-v8-handle-stack-allocated-variable-in-closure

primitive values & object values

storing values

passing parameters

comparing values

I suggest that we change the question to something sensible and remove most existing articles. What should the new question be about? Busting this common myth?

finalchild commented 4 months ago

I understand that this repository is mostly stale and stable, but are there any active maintainer who can help resolve this issue? Once the way we handle this is decided, I can work on a PR.

andrea924breaux commented 2 months ago

Thank you for provide me this kind of information it is very helpful for me. krogerfeeback.com