See this recent thread: https://esdiscuss.org/topic/are-objects-values
As far as I can tell, the answer is the answer Humpty-Dumpty gave Alice: "When I use a word, it means just what I choose it to mean — neither more nor less." :-) "Value" is used in the spec (AFAICT) to refer to primitive values and objects, and "object reference" isn't mentioned anywhere in the spec. (There's a "Reference" type, but it's used for something else.) The spec's language in this regard is conceptual and I *believe* in keeping with comp sci high-level theory (Allen Wirfs-Brock is extremely qualified in this regard); but it's also specific enough for implementations to be written unambiguously (usually). But in other contexts, you might see the term "value" used to refer to the actual thing that variables contain, properties contain, arguments contain, and that are used for the return of a function. In that sense, objects are referenced by values that identify the object (e.g., "object references"). I find this definition useful for reasoning about (and explaining) why when you pass "an object" to a function, the object isn't copied. But there's another view that even primitives are only referred to, not actually contained, by variables, etc.; just that they're immutable singletons. E.g., that `a = 2` would store a *reference* to 2 in `a`, not the actual value 2. (And indeed, I expect that's exactly what implementations do with primitive strings.) An implementaton could be written that way and be fully compliant with the spec as far as I know. Re "pass-by-value" vs. "pass-by-reference" - it has nothing to do with object references at all. The word "reference" is used for many different things. In that case, pass-by-reference is a term of art meaning that in, say, `foo(bar)`, `foo` gets a reference to the **variable** `bar` that's passed in and can change `bar`'s contents. JavaScript doesn't have that. HTH, -- T.J. Crowder On Sat, Aug 26, 2017 at 10:40 AM, Danny Niu <[email protected]> wrote: > Hi all, I've been struggling finding information on this, so let me open > by asking the following question: > > Q1: If primitive types are passed by value and objects by reference when > calling function, where is this characteristic of objects mentioned in the > standard? > > I've been trying to find answers from various sources, and I tried asking > at https://stackoverflow.com/questions/45388408 but no result had been > satisfactory. People from https://stackoverflow.com/questions/518000 > seems adamant that ES is a pass-by-value language, so I assumed the value > of objects are their individuality. > > So I tried reasoning a bit further, since it is defined in the standard > that objects are a collection of properties, its value must be the > uniqueness of such collection. And this makes sense since similar features > in other languages also implement objects as reference types. > > But is it possible that the standard intentionally left this > "implementation-defined"? So here's my second question: > > Q2: What's the rationale if any, to not explicitly require that objects be > viewed as reference when passed as arguments to functions and assigned to > variables. > > Thanks. > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

