Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

undefined string in an object?

60 views
Skip to first unread message

JRough

unread,
Sep 6, 2017, 7:33:10 PM9/6/17
to
me (JRough change)

4:31 PM (less than a minute ago)


var a={};
a["b"]=123,
a["c"]=456;
console.log(a["b"]);
undefined

var a={};
a.b=123,
a.c=456;
console.log(a.b);
undefined


Why is this object literal not defined? If it is because it was stringified how to make it an object again so you get the value? tnx,

Joao Rodrigues

unread,
Sep 9, 2017, 10:07:29 AM9/9/17
to
This object literal is being defined accordingly.
var a = {};
a["b"]=123, a["c"]=456;
^^^

There you have used the comma operator, maybe unwittingly, but it was ok
in this case.
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator>

console.log(a["b"]) is returning "123", and then undefined.

If you write console.log(a) or console.dir(a), you'll retrieve:
{ b: 123, c: 456 }

See also
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors>

--
Joao Rodrigues

Thomas 'PointedEars' Lahn

unread,
Sep 10, 2017, 10:20:55 AM9/10/17
to
Joao Rodrigues wrote:

> JRough wrote:
>> me (JRough change)
>>
>> 4:31 PM (less than a minute ago)
>>
>>
>> var a={}; a["b"]=123, a["c"]=456; console.log(a["b"]); undefined
>>
>> var a={}; a.b=123, a.c=456; console.log(a.b); undefined
>>
>>
>> Why is this object literal not defined? If it is because it was
>> stringified how to make it an object again so you get the value?
>> tnx,
>
> This object literal is being defined accordingly.

The (referred) _object_ is being defined as intended.

An object *literal* (standard term: “object _initializer_”; it is actually
_not_ listed under “11.8 Literals”[1]) is an *expression* that begins with
“{”, ends with “}”, and can be produced by the /ObjectLiteral/ production
of the ECMAScript grammar:

<http://www.ecma-international.org/ecma-262/8.0/#prod-ObjectLiteral>

[Yes, *8.0*: “ECMAScript® 2017 Language Specification
(ECMA-262, 8th edition, June 2017”.
^^^^^^^^^
Harder to keep track of this nowadays. Given the recent releases,
I just tried the greater revision number, and there it was.]

For example, “{}” is an object initializer; so are “{foo: "bar"}” and
“{"baz": 42}”.

An object is a conceptual entity only: it exists only abstractly, and in
memory only inasfar as that memory is reserved to store therein the bindings
that refer to the object, and the names and the values of its properties.

By contrast, an object *initializer* is an element of the syntax of these
programming languages.

<http://www.ecma-international.org/ecma-262/8.0/#sec-terms-and-definitions-object>

__________
[1] <http://www.ecma-international.org/ecma-262/8.0/#sec-ecmascript-language-lexical-grammar-literals>
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

John G Harris

unread,
Sep 18, 2017, 10:37:53 AM9/18/17
to
On Sun, 10 Sep 2017 16:20:43 +0200, Thomas 'PointedEars' Lahn
<Point...@web.de> wrote:

<snip>
>An object is a conceptual entity only: it exists only abstractly,
<snip>

That's a strange thing to say. All software and the constructs within
it are conceptual and abstract. Software is nothing more than a
pattern made from charge, magnetism, voltage, whatever. It is humans
who declare that that part of the pattern is a picture, that part is a
number, that part is code to tell the processor what to do, etc. And
that part is an Object.

John

Thomas 'PointedEars' Lahn

unread,
Sep 18, 2017, 11:17:57 AM9/18/17
to
John G Harris wrote:

> On Sun, 10 Sep 2017 16:20:43 +0200, Thomas 'PointedEars' Lahn
> <Point...@web.de> wrote:
> <snip>
>>An object is a conceptual entity only: it exists only abstractly,
> <snip>
>
> That's a strange thing to say. […]

Not if you read the statement *in context*.


Shaking his head,

John G Harris

unread,
Sep 19, 2017, 6:05:16 AM9/19/17
to
On Mon, 18 Sep 2017 17:17:46 +0200, Thomas 'PointedEars' Lahn
<Point...@web.de> wrote:

>John G Harris wrote:
>
>> On Sun, 10 Sep 2017 16:20:43 +0200, Thomas 'PointedEars' Lahn
>> <Point...@web.de> wrote:
>> <snip>
>>>An object is a conceptual entity only: it exists only abstractly,
>> <snip>
>>
>> That's a strange thing to say. [匽
>
>Not if you read the statement *in context*.
<snip>

In any context it reads as though objects are a special case. That is
what was a strange thing to say.

John

Thomas 'PointedEars' Lahn

unread,
Sep 19, 2017, 6:58:15 AM9/19/17
to
</killfile>

John G Harris wrote:

> On Mon, 18 Sep 2017 17:17:46 +0200, Thomas 'PointedEars' Lahn
> <Point...@web.de> wrote:
>>John G Harris wrote:
>>> On Sun, 10 Sep 2017 16:20:43 +0200, Thomas 'PointedEars' Lahn
>>> <Point...@web.de> wrote:
>>> <snip>
>>>>An object is a conceptual entity only: it exists only abstractly,
>>> <snip>
>>>
>>> That's a strange thing to say. […]
>>
>>Not if you read the statement *in context*.
> <snip>
>
> In any context it reads as though objects are a special case.

They *are* *in* *this* *context*. You can *write* and *read* source code.
You can only *think* of objects.

> That is what was a strange thing to say.

Perhaps it is my fault. I am just not able to break my explanations down to
your level of understanding.

Or you are just a troll, *playing* stupid.

In any case, you have proven once again that reading your postings is just a
waste of time for me.

<killfile>

Flng Fck

unread,
Sep 20, 2017, 3:37:48 AM9/20/17
to
Il 19/09/2017 12:58, Thomas 'PointedEars' Lahn ha scritto:
>>>>> An object is a conceptual entity only: it exists only abstractly,
>>>> <snip>
>>>>
>>>> That's a strange thing to say. […]
>>> Not if you read the statement *in context*.
>> <snip>
>>
>> In any context it reads as though objects are a special case.
> They *are* *in* *this* *context*. You can *write* and *read* source code.
> You can only *think* of objects.

Then define what "*this* *context*" is, otherwise it would be you the
one who's just trolling along

John G Harris

unread,
Sep 20, 2017, 6:30:24 AM9/20/17
to
On Tue, 19 Sep 2017 12:58:03 +0200, Thomas 'PointedEars' Lahn
<Point...@web.de> wrote:

></killfile>
>
>John G Harris wrote:
>
>> On Mon, 18 Sep 2017 17:17:46 +0200, Thomas 'PointedEars' Lahn
>> <Point...@web.de> wrote:
>>>John G Harris wrote:
>>>> On Sun, 10 Sep 2017 16:20:43 +0200, Thomas 'PointedEars' Lahn
>>>> <Point...@web.de> wrote:
>>>> <snip>
>>>>>An object is a conceptual entity only: it exists only abstractly,
>>>> <snip>
>>>>
>>>> That's a strange thing to say. [?]
>>>
>>>Not if you read the statement *in context*.
>> <snip>
>>
>> In any context it reads as though objects are a special case.
>
>They *are* *in* *this* *context*. You can *write* and *read* source code.
>You can only *think* of objects.
<snip>

Is he really saying objects are conceptual but variables and primitive
strings aren't ?

><killfile>

Hooray! I can now say anything without snide comments appearing.

John

Ben Bacarisse

unread,
Sep 20, 2017, 3:29:14 PM9/20/17
to
John G Harris <ni...@jghnorth.org.uk.invalid> writes:

> On Tue, 19 Sep 2017 12:58:03 +0200, Thomas 'PointedEars' Lahn
> <Point...@web.de> wrote:
<snip>
>><killfile>
>
> Hooray! I can now say anything without snide comments appearing.

How have you managed this? I'm seriously jealous.

--
Ben.

John G Harris

unread,
Sep 21, 2017, 11:12:40 AM9/21/17
to
<killfile> is your friend :-)

John

jonas.t...@gmail.com

unread,
Sep 22, 2017, 9:12:06 AM9/22/17
to
Can you really have a string as an index?
isn't a[] supposed to be an array, i see you guys call it object here?

Evertjan.

unread,
Sep 22, 2017, 1:20:28 PM9/22/17
to
jonas.t...@gmail.com wrote on 22 Sep 2017 in comp.lang.javascript:

> Den torsdag 7 september 2017 kl. 01:33:10 UTC+2 skrev JRough:
>> me (JRough change)
>>
>> 4:31 PM (less than a minute ago)
>>
>>
>> var a={};
>> a["b"]=123,
>> a["c"]=456;
>> console.log(a["b"]);
>> undefined
>>
>> var a={};
>> a.b=123,
>> a.c=456;

[..]

> Can you really have a string as an index?
> isn't a[] supposed to be an array, i see you guys call it object here?

An object {} and an array [] are NOT!!!!!! the same.

Why not go back to basics and study for a few .... months?



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

John G Harris

unread,
Sep 23, 2017, 5:55:50 AM9/23/17
to
On Fri, 22 Sep 2017 06:11:54 -0700 (PDT), jonas.t...@gmail.com
wrote:

>Den torsdag 7 september 2017 kl. 01:33:10 UTC+2 skrev JRough:
>> me (JRough change)
>>
>> 4:31 PM (less than a minute ago)
>>
>>
>> var a={};
>> a["b"]=123,
>> a["c"]=456;
>> console.log(a["b"]);
>> undefined
>>
>> var a={};
>> a.b=123,
>> a.c=456;
>> console.log(a.b);
>> undefined
>>
>>
>> Why is this object literal not defined? If it is because it was stringified how to make it an object again so you get the value? tnx,
>
>Can you really have a string as an index?

Yes.

a["b"]=123;
is specified by the ECMAScript Standard to mean exactly the same as
a.b=123;


>isn't a[] supposed to be an array, i see you guys call it object here?

a is an ordinary object, but you can use array notation to select a
property.

John

jonas.t...@gmail.com

unread,
Sep 23, 2017, 12:02:51 PM9/23/17
to
Thanks John i think i learned something, i see what a property is.
You say that if you have a property of an object, a["b"]=123; "b" is the property and 123 is the property value?

I can reach the variable stored by c=a["b"] and then
console.log(c);
Will write out 123?

I guess a is the object so how many properties can an object have?
Can an objects property also refer to a new object itself?
So you can make a relational chain with objects?

That somehow would need objects possible to be created on the fly without have them defined, so it probably not possible?

var a={};
a[b={}]=1,

The neat thing with arrays and indexes is that they are easily accesible, so it possible to make relational structures quite easy, i was just thinking if something similar was possible with objects.


0 new messages